]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mjson: bound the exponent in mystrtod()
authorGihyeon Ryu <rlgusryu@gmail.com>
Wed, 11 Nov 2026 10:00:12 +0000 (10:00 +0000)
committerOlivier Houchard <cognet@ci0.org>
Mon, 16 Nov 2026 14:55:56 +0000 (15:55 +0100)
The exponent is accumulated in an int without limit, so a long run of
exponent digits makes it wrap. Stop accumulating once it exceeds 100000:
the result is then already zero or infinite for a double.

This should be backported along with the previous patch.

src/mjson.c

index 9a94ed553215c7e2fce47a00b445afb001969667..2123eb433471a9c13a526d8a31596a2c79984917 100644 (file)
@@ -470,7 +470,11 @@ static double mystrtod(const char *str, int len, char **end) {
     p++;
     if (p < end_p && *p == '-') p++, neg++;
     if (p < end_p && *p == '+') p++;
-    while (p < end_p && is_digit(*p)) e = e * 10 + *p++ - '0';
+    while (p < end_p && is_digit(*p)) {
+      /* beyond this, 10^e is already infinite or zero for a double */
+      if (e < 100000) e = e * 10 + *p - '0';
+      p++;
+    }
     i = e;
     if (neg) e = -e;
 #if 0