Commit 09bbd745 by Serge Hallyn

strtoul: check errno

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: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent f371aca9
...@@ -202,9 +202,9 @@ static int _real_caps_last_cap(void) ...@@ -202,9 +202,9 @@ static int _real_caps_last_cap(void)
if ((n = read(fd, buf, 31)) >= 0) { if ((n = read(fd, buf, 31)) >= 0) {
buf[n] = '\0'; buf[n] = '\0';
errno = 0;
result = strtol(buf, &ptr, 10); result = strtol(buf, &ptr, 10);
if (!ptr || (*ptr != '\0' && *ptr != '\n') || if (!ptr || (*ptr != '\0' && *ptr != '\n') || errno != 0)
result == INT_MIN || result == INT_MAX)
result = -1; result = -1;
} }
......
...@@ -1946,9 +1946,9 @@ static int setup_caps(struct lxc_list *caps) ...@@ -1946,9 +1946,9 @@ static int setup_caps(struct lxc_list *caps)
/* try to see if it's numeric, so the user may specify /* try to see if it's numeric, so the user may specify
* capabilities that the running kernel knows about but * capabilities that the running kernel knows about but
* we don't */ * we don't */
errno = 0;
capid = strtol(drop_entry, &ptr, 10); capid = strtol(drop_entry, &ptr, 10);
if (!ptr || *ptr != '\0' || if (!ptr || *ptr != '\0' || errno != 0)
capid == INT_MIN || capid == INT_MAX)
/* not a valid number */ /* not a valid number */
capid = -1; capid = -1;
else if (capid > lxc_caps_last_cap()) else if (capid > lxc_caps_last_cap())
......
...@@ -179,8 +179,9 @@ extern int get_u16(unsigned short *val, const char *arg, int base) ...@@ -179,8 +179,9 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
if (!arg || !*arg) if (!arg || !*arg)
return -1; return -1;
errno = 0;
res = strtoul(arg, &ptr, base); res = strtoul(arg, &ptr, base);
if (!ptr || ptr == arg || *ptr || res > 0xFFFF) if (!ptr || ptr == arg || *ptr || res > 0xFFFF || errno != 0)
return -1; return -1;
*val = res; *val = res;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment