]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: do bounds check using a double comparison
authorAdam Sampson <ats@offog.org>
Wed, 9 Aug 2017 13:11:17 +0000 (14:11 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 9 Aug 2017 17:24:16 +0000 (19:24 +0200)
The fix for this in 8661a0aacc01492e0436275ff36a21734f2541bb wasn't
complete: if the parsed number in num is larger than will fit in a long,
the conversion is undefined behaviour (causing test1427 to fail for me
on IA32 with GCC 7.1, although it passes on AMD64 and ARMv7).  Getting
rid of the cast means the comparison will be done using doubles.

It might make more sense for the max argument to also be a double...

Fixes #1750
Closes #1749

src/tool_paramhlp.c

index b9dedc989e529b1d4382f0ba01854790e0a1bb3a..85c5e79a7e6babae495464c37d1bcd453130f91a 100644 (file)
@@ -218,7 +218,7 @@ static ParameterError str2double(double *val, const char *str, long max)
     num = strtod(str, &endptr);
     if(errno == ERANGE)
       return PARAM_NUMBER_TOO_LARGE;
-    if((long)num > max) {
+    if(num > max) {
       /* too large */
       return PARAM_NUMBER_TOO_LARGE;
     }