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 16374c37 Fix issue #1389 - Server crash on using null operand for access operators (#1390) 16374c37 is described below commit 16374c37f975bf1971e3020d37372e58f44ead95 Author: Zainab Saad <105385638+zainab-s...@users.noreply.github.com> AuthorDate: Thu Nov 9 22:10:37 2023 +0500 Fix issue #1389 - Server crash on using null operand for access operators (#1390) - The issue was due to code not handling null values as LHS operands for access operators(->, ->>) Added check for this case and included regression tests --- regress/expected/jsonb_operators.out | 48 ++++++++++++++++++++++++++++++++++++ regress/sql/jsonb_operators.sql | 12 +++++++++ src/backend/utils/adt/agtype.c | 11 ++++++--- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/regress/expected/jsonb_operators.out b/regress/expected/jsonb_operators.out index 45807bc2..8e2f7a20 100644 --- a/regress/expected/jsonb_operators.out +++ b/regress/expected/jsonb_operators.out @@ -938,6 +938,30 @@ SELECT '{"a": 9, "b": 11, "c": {"ca": [[], {}, null]}, "d": true, "1": false}':: (1 row) +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> '"1"'::agtype; + ?column? +---------- + +(1 row) + +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> 1::text; + ?column? +---------- + +(1 row) + +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> '"a"'; + ?column? +---------- + +(1 row) + +SELECT 'null'::agtype -> '"1"'; + ?column? +---------- + +(1 row) + -- LHS is an array SELECT '["a","b","c",[1,2],null]'::agtype -> '0'::agtype; ?column? @@ -1241,6 +1265,30 @@ SELECT '{"a": [{"b": "c"}, {"b": "cc"}]}'::agtype ->> null::int; (1 row) +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> '"1"'::agtype; + ?column? +---------- + +(1 row) + +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> 1::text; + ?column? +---------- + +(1 row) + +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> '"a"'; + ?column? +---------- + +(1 row) + +SELECT 'null'::agtype ->> '"1"'; + ?column? +---------- + +(1 row) + -- LHS is an array SELECT '["a","b","c",[1,2],null]'::agtype ->> 0; ?column? diff --git a/regress/sql/jsonb_operators.sql b/regress/sql/jsonb_operators.sql index aa79753c..7cf58acd 100644 --- a/regress/sql/jsonb_operators.sql +++ b/regress/sql/jsonb_operators.sql @@ -223,6 +223,12 @@ SELECT '{"a": [{"b": "c"}, {"b": "cc"}]}'::agtype -> null::int; SELECT '{"a": [-1, -2, -3]}'::agtype -> '"a"'::text; SELECT '{"a": 9, "b": 11, "c": {"ca": [[], {}, null]}, "d": true, "1": false}'::agtype -> '1'::text::agtype; +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> '"1"'::agtype; +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> 1::text; +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> '"a"'; + +SELECT 'null'::agtype -> '"1"'; + -- LHS is an array SELECT '["a","b","c",[1,2],null]'::agtype -> '0'::agtype; SELECT '["a","b","c",[1,2],null]'::agtype -> 1; @@ -288,6 +294,12 @@ SELECT '{"1": -1.99, "a": 1, "b": 2, "c": {"d": [{}, [[[], [9]]]]}, "1": true}': SELECT '{"a": [{"b": "c"}, {"b": "cc"}]}'::agtype ->> null::text; SELECT '{"a": [{"b": "c"}, {"b": "cc"}]}'::agtype ->> null::int; +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> '"1"'::agtype; +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> 1::text; +SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> '"a"'; + +SELECT 'null'::agtype ->> '"1"'; + -- LHS is an array SELECT '["a","b","c",[1,2],null]'::agtype ->> 0; SELECT '["a","b","c",[1,2],null]'::agtype ->> '1'::agtype; diff --git a/src/backend/utils/adt/agtype.c b/src/backend/utils/adt/agtype.c index c73d066f..45e1e606 100644 --- a/src/backend/utils/adt/agtype.c +++ b/src/backend/utils/adt/agtype.c @@ -3644,9 +3644,14 @@ Datum agtype_object_field_impl(FunctionCallInfo fcinfo, agtype *agtype_in, if (AGT_ROOT_IS_SCALAR(agtype_in)) { - process_agtype = - agtype_value_to_agtype(extract_entity_properties(agtype_in, - false)); + agtype_value *process_agtv = extract_entity_properties(agtype_in, + false); + if (!process_agtv) + { + PG_RETURN_NULL(); + } + + process_agtype = agtype_value_to_agtype(process_agtv); } else {