reject negative after whitespace in json_parse_uint64

This commit is contained in:
Javid Khan
2026-08-17 20:37:45 +05:30
parent 81092b3072
commit 510d68bd35
3 changed files with 13 additions and 1 deletions
+7 -1
View File
@@ -263,7 +263,13 @@ int json_parse_uint64(const char *buf, uint64_t *retval)
uint64_t val;
errno = 0;
while (*buf == ' ')
/* strtoull() skips leading whitespace and then quietly negates a
* leading '-', wrapping the result into a huge value. We only skipped
* spaces here, so a '-' behind a tab/newline/etc slipped past the check
* below. Skip the same whitespace set strtoull() does so the rejection
* actually holds. */
while (*buf == ' ' || *buf == '\t' || *buf == '\n' || *buf == '\v' || *buf == '\f' ||
*buf == '\r')
buf++;
if (*buf == '-')
return 1; /* error: uint cannot be negative */