From: Gihyeon Ryu Date: Wed, 11 Nov 2026 10:00:12 +0000 (+0000) Subject: BUG/MINOR: mjson: bound the exponent in mystrtod() X-Git-Tag: v3.5-dev13~61 X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=15d860b81a785dc47c916c38647e772ad22c1c81;p=haproxy.git BUG/MINOR: mjson: bound the exponent in mystrtod() 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. --- diff --git a/src/mjson.c b/src/mjson.c index 9a94ed553..2123eb433 100644 --- a/src/mjson.c +++ b/src/mjson.c @@ -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