From: Dmitry V. Levin Date: Wed, 30 Nov 2016 14:39:02 +0000 (+0000) Subject: util: fix integer overflow check in string_to_uint_ex X-Git-Tag: v4.15~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f2980bd2c077be67fbcf680cdb0cb40d342208e;p=strace util: fix integer overflow check in string_to_uint_ex * util.c (string_to_uint_ex): Fix the check for integer overflow on systems where LONG_MAX == INT_MAX. --- diff --git a/util.c b/util.c index a3c505d6..9976c76e 100644 --- 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)))