Skip to content

Commit

Permalink
Fix issue 1956 - null key name passed. (#1960)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrgemignani authored Jul 9, 2024
1 parent b4df96a commit ff22d76
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -8416,6 +8416,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": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98, "n99": 99, "n100": 100, "n101": 101}}::vertex
(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
--
Expand Down
7 changes: 7 additions & 0 deletions regress/sql/expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3424,6 +3424,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, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98, n99: 99, n100: 100, n101: 101} ) RETURN u $$) as (result agtype);
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
--
Expand Down
10 changes: 9 additions & 1 deletion src/backend/utils/adt/agtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,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 */
Expand Down Expand Up @@ -6852,7 +6860,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)
{
Expand Down

0 comments on commit ff22d76

Please sign in to comment.