This is an automated email from the ASF dual-hosted git repository.
mtaha pushed a commit to branch PG13
in repository https://gitbox.apache.org/repos/asf/age.git
The following commit(s) were added to refs/heads/PG13 by this push:
new a32505c3 Fix issue 1956 - null key name passed. (#1963)
a32505c3 is described below
commit a32505c3bbc6c55bb697d7c2e1a7563459023f22
Author: John Gemignani <[email protected]>
AuthorDate: Mon Jul 8 23:10:39 2024 -0700
Fix issue 1956 - null key name passed. (#1963)
Fixed issue 1956 - Server crashes when executing
SELECT agtype_build_map('null'::agtype, 1);
This issue was due to a missing check for AGTV_NULL values. The
check was added and the issue was corrected.
Added regression tests.
---
regress/expected/expr.out | 9 +++++++++
regress/sql/expr.sql | 7 +++++++
src/backend/utils/adt/agtype.c | 10 +++++++++-
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/regress/expected/expr.out b/regress/expected/expr.out
index 2a308881..275d60a0 100644
--- a/regress/expected/expr.out
+++ b/regress/expected/expr.out
@@ -8345,6 +8345,15 @@ SELECT * FROM cypher('expanded_map', $$ MATCH (u) RETURN
u $$) as (result agtype
{"id": 281474976710664, "label": "", "properties": {"n0": 0, "n1": 1, "n2":
2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10,
"n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17,
"n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24,
"n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31,
"n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38,
"n39": 39, "n40": 40, "n41": 4 [...]
(8 rows)
+--
+-- Issue 1956 - null key
+--
+SELECT agtype_build_map('null'::agtype, 1);
+ERROR: argument 1: key must not be null
+SELECT agtype_build_map(null, 1);
+ERROR: argument 1: key must not be null
+SELECT agtype_build_map('name', 'John', 'null'::agtype, 1);
+ERROR: argument 3: key must not be null
--
-- Cleanup
--
diff --git a/regress/sql/expr.sql b/regress/sql/expr.sql
index 37fde2cd..f8334a4c 100644
--- a/regress/sql/expr.sql
+++ b/regress/sql/expr.sql
@@ -3397,6 +3397,13 @@ SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0:
0, n1: 1, n2: 2, n3: 3, n
SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3,
n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13,
n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22:
22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30,
n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39:
39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47,
n48: 48, n49: 49, n50: 50, n5 [...]
SELECT * FROM cypher('expanded_map', $$ MATCH (u) RETURN u $$) as (result
agtype);
+--
+-- Issue 1956 - null key
+--
+SELECT agtype_build_map('null'::agtype, 1);
+SELECT agtype_build_map(null, 1);
+SELECT agtype_build_map('name', 'John', 'null'::agtype, 1);
+
--
-- Cleanup
--
diff --git a/src/backend/utils/adt/agtype.c b/src/backend/utils/adt/agtype.c
index 4fa0dc2a..d1ab0122 100644
--- a/src/backend/utils/adt/agtype.c
+++ b/src/backend/utils/adt/agtype.c
@@ -2402,6 +2402,14 @@ static agtype_value
*agtype_build_map_as_agtype_value(FunctionCallInfo fcinfo)
agtv = tostring_helper(args[i], types[i],
"agtype_build_map_as_agtype_value");
+ if (agtv == NULL)
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("argument %d: key must not be null", i + 1)));
+
+ }
+
result.res = push_agtype_value(&result.parse_state, WAGT_KEY,
agtv);
/* free the agtype_value from tostring_helper */
@@ -6804,7 +6812,7 @@ Datum age_tostring(PG_FUNCTION_ARGS)
/*
* Helper function to take any valid type and convert it to an agtype string.
- * Returns NULL for NULL output.
+ * Returns NULL for NULL input.
*/
static agtype_value *tostring_helper(Datum arg, Oid type, char *msghdr)
{