From ea89c7b1ee350e0d308f0f1f9a00fd234afb183c Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Fri, 20 Oct 2023 23:22:38 +0800 Subject: [PATCH] Fix parsing JSON numbers. --- src/util/json_parser.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/json_parser.c b/src/util/json_parser.c index 724c99a353..e635fbfef1 100644 --- a/src/util/json_parser.c +++ b/src/util/json_parser.c @@ -278,9 +278,18 @@ static int __parse_json_number(const char *cursor, const char **end, if (*p == '-') p++; + if (!isdigit(*p)) + return -2; + if (*p == '0' && (isdigit(p[1]) || p[1] == 'X' || p[1] == 'x')) return -2; + while (isdigit(*++p)) + ; + + if (*p == '.' && !isdigit(*(p + 1))) + return -2; + *num = strtod(cursor, (char **)end); if (*end == cursor) return -2;