Skip to content

Commit

Permalink
Fix parsing JSON numbers. Should not accept '1.', '-.1' as a number.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Oct 20, 2023
1 parent 3f45098 commit e9430b1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions json_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,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;
Expand Down

0 comments on commit e9430b1

Please sign in to comment.