Commit af91945
committed
Critical: fix inverted logic here
strcmp(str, "") returns 0 (false) when str is empty, meaning the check is
inverted: it returns NULL when parsing succeeds and continues when parsing
fails. This allows non-numeric strings to pass through as array indices, leading
to type confusion and potentially incorrect memory access.
The strcmp logic handles most cases correctly (non-numeric strings return NULL,
valid integers pass through). However, the empty string "" is accepted as a
valid array index of 0: [10, 20, 30] #> '[""]' returns 10 instead of NULL. This
occurs because strtol("") sets lindex=0 and str="", so strcmp("", "") returns 0,
bypassing the error check.
Signed-off-by: David Christensen <[email protected]>1 parent f1a9b1d commit af91945
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2098 | 2098 | | |
2099 | 2099 | | |
2100 | 2100 | | |
2101 | | - | |
| 2101 | + | |
2102 | 2102 | | |
2103 | 2103 | | |
2104 | 2104 | | |
| |||
0 commit comments