From 9f2980bd2c077be67fbcf680cdb0cb40d342208e Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 30 Nov 2016 14:39:02 +0000 Subject: [PATCH] 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. --- util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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))) -- 2.40.0