Repository navigation
Conversation
Tighten number parsing in json_to_s64 and json_to_double to conform strictly to the JSON specification (RFC 8259). Explicitly reject leading '+' signs in json_to_s64, and reject leading '+', hexadecimal floats, and special values like 'inf' or 'nan' in json_to_double. Add unit tests in common/test/run-json.c covering both valid formats and invalid non-JSON inputs. Changelog-None Fixes ElementsProject#9377
805e9c0 to
98b2316
Compare
| char *end; | ||
|
|
||
| /* JSON numbers cannot have an explicit '+' sign or empty string. */ | ||
| if (p[0] == '\0' || p[0] == '+') |
There was a problem hiding this comment.
This is redundant, the following two if's already cause these to retrun false.
| if (*p == '-') | ||
| p++; | ||
|
|
||
| /* Must begin with a digit (rejects 'inf', 'nan', '0x...', etc.) */ |
There was a problem hiding this comment.
nit: the 0 in 0x is a digit and would be accepted here. 0x would be rejected later though
| p++; | ||
|
|
||
| /* Must begin with a digit (rejects 'inf', 'nan', '0x...', etc.) */ | ||
| if (*p < '0' || *p > '9') |
There was a problem hiding this comment.
cisdigit(*p) is preferred here
CLN builds jsmn with Inputs rejected by
Check the prefix checks in
|
Summary
Resolves #9377.
Tightens number parsing in
json_to_s64andjson_to_doubleaccording to the JSON specification (RFC 8259):json_to_s64: explicitly rejects leading+signs (+1,+0,+1555).json_to_double: explicitly rejects leading+, requires an optional-followed immediately by a digit, and rejects hexadecimal floating points (0x...),inf, andnan.common/test/run-json.c: adds negative test assertions forjson_to_s64andjson_to_u64, and introduces comprehensive unit tests forjson_to_doublecovering valid numbers and invalid non-JSON inputs.Changelog-None