- Set errno = 0 before the call. Otherwise, it may contain anything.
- ERANGE is not the only possible errno value of these functions. They
can also set it to EINVAL.
- Any errno value after these calls is bad; just compare against 0.
- Don't check for the return value; just errno. This function is
guaranteed to not modify errno on success (POSIX).
- Check endptr == str, which may or may not set EINVAL.
Suggested-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
char *endptr;
errno = 0;
- val = strtoll (gidstr, &endptr, 10);
+ val = strtoll(gidstr, &endptr, 10);
if ( ('\0' == *gidstr)
|| ('\0' != *endptr)
- || (ERANGE == errno)
+ || (0 != errno)
|| (/*@+longintegral@*/val != (gid_t)val)/*@=longintegral@*/) {
return 0;
}
char *endptr;
errno = 0;
- val = strtoll (pidstr, &endptr, 10);
+ val = strtoll(pidstr, &endptr, 10);
if ( ('\0' == *pidstr)
|| ('\0' != *endptr)
- || (ERANGE == errno)
+ || (0 != errno)
|| (val < 1)
|| (/*@+longintegral@*/val != (pid_t)val)/*@=longintegral@*/) {
return 0;
dev_t proc_st_dev, proc_st_rdev;
errno = 0;
- val = strtoll (pidfdstr, &endptr, 10);
+ val = strtoll(pidfdstr, &endptr, 10);
if ( ('\0' == *pidfdstr)
|| ('\0' != *endptr)
- || (ERANGE == errno)
+ || (0 != errno)
|| (val < 0)
|| (/*@+longintegral@*/val != (int)val)/*@=longintegral@*/) {
return -1;
char *endptr;
errno = 0;
- val = strtoll (uidstr, &endptr, 10);
+ val = strtoll(uidstr, &endptr, 10);
if ( ('\0' == *uidstr)
|| ('\0' != *endptr)
- || (ERANGE == errno)
+ || (0 != errno)
|| (/*@+longintegral@*/val != (uid_t)val)/*@=longintegral@*/) {
return 0;
}
}
errno = 0;
- gid = strtoll (grname, &endptr, 10);
+ gid = strtoll(grname, &endptr, 10);
if ( ('\0' != *grname)
&& ('\0' == *endptr)
- && (ERANGE != errno)
+ && (0 == errno)
&& (/*@+longintegral@*/gid == (gid_t)gid)/*@=longintegral@*/) {
return xgetgrgid (gid);
}
char *endptr;
errno = 0;
- val = strtol (numstr, &endptr, 0);
- if (('\0' == *numstr) || ('\0' != *endptr) || (ERANGE == errno)) {
+ val = strtol(numstr, &endptr, 0);
+ if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno)) {
return 0;
}
return 0;
}
errno = 0;
- n = strtoul (&range[1], &endptr, 10);
- if (('\0' != *endptr) || (ERANGE == errno)) {
+ n = strtoul(&range[1], &endptr, 10);
+ if (('\0' != *endptr) || (0 != errno)) {
/* invalid */
return 0;
}
*max = n;
} else {
errno = 0;
- n = strtoul (range, &endptr, 10);
- if (ERANGE == errno) {
+ n = strtoul(range, &endptr, 10);
+ if (endptr == range || 0 != errno) {
/* invalid */
return 0;
}
*has_min = true;
*min = n;
errno = 0;
- n = strtoul (endptr, &endptr, 10);
+ n = strtoul(endptr, &endptr, 10);
if ( ('\0' != *endptr)
- || (ERANGE == errno)) {
+ || (0 != errno)) {
/* invalid */
return 0;
}
return fallback;
errno = 0;
- epoch = strtoull (source_date_epoch, &endptr, 10);
- if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
- || (errno != 0 && epoch == 0)) {
+ epoch = strtoull(source_date_epoch, &endptr, 10);
+ if (errno != 0) {
fprintf (shadow_logfd,
_("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n"),
strerror(errno));
char *endptr;
errno = 0;
- val = strtoul (numstr, &endptr, 0);
+ val = strtoul(numstr, &endptr, 0);
if ( ('\0' == *numstr)
|| ('\0' != *endptr)
- || (ERANGE == errno)
+ || (0 != errno)
) {
return 0;
}
* Also, we are limited to base 10 here (hex numbers will not
* work with the limit string parser as is anyway)
*/
+ errno = 0;
l = strtol(value, &endptr, 10);
- if (value == endptr) {
- /* No argument at all. No-op.
- * FIXME: We could instead throw an error, though.
- */
- return 0;
- }
+ if (value == endptr || errno != 0)
+ return 0; // FIXME: We could instead throw an error, though.
+
if (__builtin_mul_overflow(l, multiplier, &limit)) {
/* FIXME: Again, silent error handling...
* Wouldn't screaming make more sense?
gid = strtoll(grname, &endptr, 10);
if ( ('\0' != *grname)
&& ('\0' == *endptr)
- && (ERANGE != errno)
+ && (0 == errno)
&& (gid == (gid_t)gid))
{
return prefix_getgrgid(gid);
owner = argv[1];
check_uids = argv[2][0] == 'u';
+ errno = 0;
start = strtoul(argv[3], NULL, 10);
- if (start == ULONG_MAX && errno == ERANGE)
+ if (errno != 0)
exit(1);
count = strtoul(argv[4], NULL, 10);
- if (count == ULONG_MAX && errno == ERANGE)
+ if (errno != 0)
exit(1);
if (check_uids) {
if (have_sub_uids(owner, start, count))
errno = 0;
first = strtoll(str, &pos, 10);
- if (('\0' == *str) || ('-' != *pos ) || (ERANGE == errno) ||
+ if (('\0' == *str) || ('-' != *pos ) || (0 != errno) ||
(first != (unsigned long)first))
goto out;
errno = 0;
last = strtoll(pos + 1, &pos, 10);
- if (('\0' != *pos ) || (ERANGE == errno) ||
+ if (('\0' != *pos ) || (0 != errno) ||
(last != (unsigned long)last))
goto out;