]> granicus.if.org Git - strace/commitdiff
util: fix integer overflow check in string_to_uint_ex
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 30 Nov 2016 14:39:02 +0000 (14:39 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 30 Nov 2016 16:52:05 +0000 (16:52 +0000)
* util.c (string_to_uint_ex): Fix the check for integer overflow
on systems where LONG_MAX == INT_MAX.

util.c

diff --git a/util.c b/util.c
index a3c505d67b8eaf9912a84c70dcb83a41f223fc2c..9976c76e628afc3e3b1c7ed8cf77de4b926f76bb 100644 (file)
--- a/util.c
+++ b/util.c
@@ -53,9 +53,11 @@ string_to_uint_ex(const char *const str, char **const endptr,
        if (!*str)
                return -1;
 
+       errno = 0;
        val = strtol(str, &end, 10);
 
-       if (str == end || val < 0 || (unsigned long) val > max_val)
+       if (str == end || val < 0 || (unsigned long) val > max_val
+           || (val == LONG_MAX && errno == ERANGE))
                return -1;
 
        if (*end && (!accepted_ending || !strchr(accepted_ending, *end)))