Ban zero-length delimited identifiers. pg_plan_advice
authorRobert Haas <[email protected]>
Fri, 12 Dec 2025 17:22:08 +0000 (12:22 -0500)
committerRobert Haas <[email protected]>
Fri, 12 Dec 2025 17:22:08 +0000 (12:22 -0500)
contrib/pg_plan_advice/expected/syntax.out
contrib/pg_plan_advice/pgpa_scanner.l
contrib/pg_plan_advice/sql/syntax.sql

index 36200c8935009001da5a907f55556b21a4ddc260..eec02980896d51f9160eff808fe9d5aa08c31b9e 100644 (file)
@@ -84,6 +84,12 @@ DETAIL:  Could not parse advice: syntax error at end of input
 SET pg_plan_advice.advice = 'SEQ_SCAN("';
 ERROR:  invalid value for parameter "pg_plan_advice.advice": "SEQ_SCAN(""
 DETAIL:  Could not parse advice: unterminated quoted identifier at end of input
+SET pg_plan_advice.advice = 'SEQ_SCAN("")';
+ERROR:  invalid value for parameter "pg_plan_advice.advice": "SEQ_SCAN("")"
+DETAIL:  Could not parse advice: zero-length delimited identifier at or near """
+SET pg_plan_advice.advice = 'SEQ_SCAN("a"';
+ERROR:  invalid value for parameter "pg_plan_advice.advice": "SEQ_SCAN("a""
+DETAIL:  Could not parse advice: syntax error at end of input
 SET pg_plan_advice.advice = 'SEQ_SCAN(#';
 ERROR:  invalid value for parameter "pg_plan_advice.advice": "SEQ_SCAN(#"
 DETAIL:  Could not parse advice: syntax error at or near "#"
index be7d7ba13a614dfe67586a222f92272ae3643a72..c49b29d906daddb2464613319b5bb8463fee3ac3 100644 (file)
@@ -189,6 +189,9 @@ xcinside            [^*/]+
 
 <xd>{xdstop}   {
                                        BEGIN(INITIAL);
+                                       if (yyextra->litbuf.len == 0)
+                                               pgpa_yyerror(result, parse_error_msg_p, yyscanner,
+                                                                        "zero-length delimited identifier");
                                        yylval->str = pstrdup(yyextra->litbuf.data);
                                        return TOK_IDENT;
                                }
index 5f86ecf43ba3656521261effbf65a8e0706cd425..0692dc895caecf81f7676bac9f62b5d85c200ffe 100644 (file)
@@ -26,6 +26,8 @@ SET pg_plan_advice.advice = 'SEQUENTIAL_SCAN(x)';
 SET pg_plan_advice.advice = 'SEQ_SCAN';
 SET pg_plan_advice.advice = 'SEQ_SCAN(';
 SET pg_plan_advice.advice = 'SEQ_SCAN("';
+SET pg_plan_advice.advice = 'SEQ_SCAN("")';
+SET pg_plan_advice.advice = 'SEQ_SCAN("a"';
 SET pg_plan_advice.advice = 'SEQ_SCAN(#';
 SET pg_plan_advice.advice = '()';
 SET pg_plan_advice.advice = '123';