From: Serge Hallyn Date: Thu, 24 Oct 2013 16:35:55 +0000 (-0500) Subject: strtoul: check errno X-Git-Tag: lxc-1.0.0.alpha3~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09bbd74578af3a039325c273a3bd7e54c9c79482;p=thirdparty%2Flxc.git 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: Serge Hallyn --- diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 89b87afc2..9afd6ac9e 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -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; } diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 0724e3f5a..5560a38ca 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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()) diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 17ac74cb4..9e2e32614 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -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;