This is an automated email from the ASF dual-hosted git repository. jgemignani pushed a commit to branch PG12 in repository https://gitbox.apache.org/repos/asf/age.git
commit eda403d69d94030244d6cb384985c4a55571fd83 Author: John Gemignani <[email protected]> AuthorDate: Wed Mar 1 10:43:30 2023 -0800 Fix cypher function input argument checks (issue #718) Fixed issue #718 which was due to a lack of input checks for an edge case and added regression tests. Addition of the driver parameter patch caused 2 additional edge cases that needed to be checked - SELECT * FROM cypher() AS (result agtype); SELECT * FROM cypher(NULL) AS (result agtype); --- regress/expected/analyze.out | 5 +++++ regress/sql/analyze.sql | 4 ++++ src/backend/parser/cypher_analyze.c | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/regress/expected/analyze.out b/regress/expected/analyze.out index 5b248385..676dab9d 100644 --- a/regress/expected/analyze.out +++ b/regress/expected/analyze.out @@ -119,6 +119,11 @@ SELECT * FROM cypher(NULL, NULL) AS (result agtype); ERROR: unexpected character at or near "$" LINE 1: SELECT * FROM cypher(NULL, NULL) AS (result agtype); ^ +-- should return errors +SELECT * FROM cypher() AS (result agtype); +ERROR: cypher function requires a minimum of 2 arguments +SELECT * FROM cypher(NULL) AS (result agtype); +ERROR: cypher function requires a minimum of 2 arguments -- drop graphs SELECT * FROM drop_graph('analyze', true); NOTICE: drop cascades to 2 other objects diff --git a/regress/sql/analyze.sql b/regress/sql/analyze.sql index 881ef3ff..1da70b23 100644 --- a/regress/sql/analyze.sql +++ b/regress/sql/analyze.sql @@ -52,6 +52,10 @@ SELECT * FROM cypher(NULL, NULL) AS (result agtype); SELECT * FROM age_prepare_cypher('analyze', '$$ $$'); SELECT * FROM cypher(NULL, NULL) AS (result agtype); +-- should return errors +SELECT * FROM cypher() AS (result agtype); +SELECT * FROM cypher(NULL) AS (result agtype); + -- drop graphs SELECT * FROM drop_graph('analyze', true); diff --git a/src/backend/parser/cypher_analyze.c b/src/backend/parser/cypher_analyze.c index b67eb641..c321f231 100644 --- a/src/backend/parser/cypher_analyze.c +++ b/src/backend/parser/cypher_analyze.c @@ -329,6 +329,15 @@ static void convert_cypher_to_subquery(RangeTblEntry *rte, ParseState *pstate) parser_errposition(pstate, exprLocation((Node *)funcexpr)))); } + /* verify that we have 2 input parameters as it is possible to get 1 or 0 */ + if (funcexpr->args == NULL || list_length(funcexpr->args) < 2) + { + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("cypher function requires a minimum of 2 arguments"), + parser_errposition(pstate, -1))); + } + /* get our first 2 arguments */ arg1 = linitial(funcexpr->args); arg2 = lsecond(funcexpr->args);
