In a few places we checked for LONG_MIN or LONG_MAX as indication
that strtoul failed. That's not reliable. As suggested in the
manpage, switch to checking errno value.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
if ((n = read(fd, buf, 31)) >= 0) {
buf[n] = '\0';
+ errno = 0;
result = strtol(buf, &ptr, 10);
- if (!ptr || (*ptr != '\0' && *ptr != '\n') ||
- result == INT_MIN || result == INT_MAX)
+ if (!ptr || (*ptr != '\0' && *ptr != '\n') || errno != 0)
result = -1;
}
/* try to see if it's numeric, so the user may specify
* capabilities that the running kernel knows about but
* we don't */
+ errno = 0;
capid = strtol(drop_entry, &ptr, 10);
- if (!ptr || *ptr != '\0' ||
- capid == INT_MIN || capid == INT_MAX)
+ if (!ptr || *ptr != '\0' || errno != 0)
/* not a valid number */
capid = -1;
else if (capid > lxc_caps_last_cap())
if (!arg || !*arg)
return -1;
+ errno = 0;
res = strtoul(arg, &ptr, base);
- if (!ptr || ptr == arg || *ptr || res > 0xFFFF)
+ if (!ptr || ptr == arg || *ptr || res > 0xFFFF || errno != 0)
return -1;
*val = res;