Skip to content

Commit af91945

Browse files
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

File tree

src/backend/utils/adt/agtype_ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@ static Datum get_agtype_path_all(FunctionCallInfo fcinfo, bool as_text)
20982098
char* str = NULL;
20992099
lindex = strtol(cur_key->val.string.val, &str, 10);
21002100

2101-
if (strcmp(str, ""))
2101+
if (strcmp(str, "") != 0)
21022102
{
21032103
PG_RETURN_NULL();
21042104
}

0 commit comments

Comments
 (0)