tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Reuse strtonum(3) and reallocarray(3) from OpenBSD



On Dec 28,  6:12pm, n54%gmx.com@localhost ("Kamil Rytarowski") wrote:
-- Subject: Re: Reuse strtonum(3) and reallocarray(3) from OpenBSD

| A programmer didn't care about errors (ERANGE, EINVAL) and silently skips errno checking.
| Nobody enforces it on him or her. This code is vulnerable to overflows and (at least to me)
| more difficult to maintain (undesired pointer magic).
| 
| numlines = fullstrtou(p, 10, 1, 1, UINT_MAX);
| if (errno)
| errx(1, "%s: illegal line count.", p);
| 
| (yes <errno.h> is already pulled in, and we don't care whether it was partial, out of range, overflow...)
| 

Just add:

	int fd = open("/does/not/exist", O_RDONLY);

before your newfangled fullstrtou().  Also you are using errx()
instead of err() that hides the message from errno.

christos


Home | Main Index | Thread Index | Old Index