]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
strtoul: check errno
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 24 Oct 2013 16:35:55 +0000 (11:35 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 24 Oct 2013 16:35:55 +0000 (11:35 -0500)
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>
src/lxc/caps.c
src/lxc/conf.c
src/lxc/utils.c

index 89b87afc216e0d5c37c10cbbab2facb379fa6430..9afd6ac9e22711b2b5a2e5fb8155a10e3772a4ae 100644 (file)
@@ -202,9 +202,9 @@ static int _real_caps_last_cap(void)
 
                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;
                }
 
index 0724e3f5ae14c959ebf4a76a7d9ed321ed8dd150..5560a38cad1b7d76cf6ce85d5bc2619bc68b7dee 100644 (file)
@@ -1946,9 +1946,9 @@ static int setup_caps(struct lxc_list *caps)
                        /* 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())
index 17ac74cb47db8218116375214c4be9c169f77890..9e2e326146835c4c734eb5737e4cb7750a0bbd5e 100644 (file)
@@ -179,8 +179,9 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
        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;