This is an automated email from the ASF dual-hosted git repository.
jgemignani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/age.git
The following commit(s) were added to refs/heads/master by this push:
new 0c9a5278 Fix null pointer handling in array iteration (#2313)
0c9a5278 is described below
commit 0c9a527860cde710175fc9c171b6bbe9aaed45d6
Author: Maxim Korotkov <[email protected]>
AuthorDate: Fri Feb 13 21:57:51 2026 +0300
Fix null pointer handling in array iteration (#2313)
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 <[email protected]>
---
src/backend/utils/adt/agtype.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/src/backend/utils/adt/agtype.c b/src/backend/utils/adt/agtype.c
index c552727d..2526f41f 100644
--- a/src/backend/utils/adt/agtype.c
+++ b/src/backend/utils/adt/agtype.c
@@ -7500,19 +7500,12 @@ Datum age_tostringlist(PG_FUNCTION_ARGS)
/* TODO: check element's type, it's value, and convert it to string if
possible. */
elem = get_ith_agtype_value_from_container(&agt_arg->root, i);
string_elem.type = AGTV_STRING;
+ enum agtype_value_type elem_type = elem ? elem->type : AGTV_NULL;
- switch (elem->type)
+ switch (elem_type)
{
case AGTV_STRING:
- if(!elem)
- {
- string_elem.type = AGTV_NULL;
-
- agis_result.res = push_agtype_value(&agis_result.parse_state,
- WAGT_ELEM, &string_elem);
- }
-
string_elem.val.string.val = elem->val.string.val;
string_elem.val.string.len = elem->val.string.len;