Skip to content

Commit 535e5ea

Browse files
Fix null pointer handling in array iteration
Previously, when iterating through an agtype container, the code would access `elem->val` even when `elem` was null. This adds a null check to set the result type to AGTV_NULL when the element is null, preventing a potential segmentation fault. Fixes: 4274f10 ("Added the toStringList() function (#1084)") Found by PostgresPro. Signed-off-by: Maksim Korotkov <m.korotkov@postgrespro.ru>
1 parent 1702ae0 commit 535e5ea

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

src/backend/utils/adt/agtype.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7500,19 +7500,12 @@ Datum age_tostringlist(PG_FUNCTION_ARGS)
75007500
/* TODO: check element's type, it's value, and convert it to string if possible. */
75017501
elem = get_ith_agtype_value_from_container(&agt_arg->root, i);
75027502
string_elem.type = AGTV_STRING;
7503+
agtype_value_type elem_type = elem ? elem->type : AGTV_NULL;
75037504

7504-
switch (elem->type)
7505+
switch (elem_type)
75057506
{
75067507
case AGTV_STRING:
75077508

7508-
if(!elem)
7509-
{
7510-
string_elem.type = AGTV_NULL;
7511-
7512-
agis_result.res = push_agtype_value(&agis_result.parse_state,
7513-
WAGT_ELEM, &string_elem);
7514-
}
7515-
75167509
string_elem.val.string.val = elem->val.string.val;
75177510
string_elem.val.string.len = elem->val.string.len;
75187511

0 commit comments

Comments
 (0)