diff options
author | Richard Guo <rguo@postgresql.org> | 2025-05-15 17:09:04 +0900 |
---|---|---|
committer | Richard Guo <rguo@postgresql.org> | 2025-05-15 17:09:04 +0900 |
commit | fe29b2a1dab2b3d81e6c350679b7d9b0e1c8c850 (patch) | |
tree | d3178a4ad1e430730f13d6e5cc57356f5be5414a /src/backend | |
parent | 2c0ed86d393670c7054d051490063de771f1791e (diff) | |
download | postgresql-fe29b2a1dab2b3d81e6c350679b7d9b0e1c8c850.tar.gz postgresql-fe29b2a1dab2b3d81e6c350679b7d9b0e1c8c850.zip |
Fix Assert failure in XMLTABLE parser
In an XMLTABLE expression, columns can be marked NOT NULL, and the
parser internally fabricates an option named "is_not_null" to
represent this. However, the parser also allows users to specify
arbitrary option names. This creates a conflict: a user can
explicitly use "is_not_null" as an option name and assign it a
non-Boolean value, which violates internal assumptions and triggers an
assertion failure.
To fix, this patch checks whether a user-supplied name collides with
the internally reserved option name and raises an error if so.
Additionally, the internal name is renamed to "__pg__is_not_null" to
further reduce the risk of collision with user-defined names.
Reported-by: Евгений Горбанев <gorbanyoves@basealt.ru>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/6bac9886-65bf-4cec-96bd-e304159f28db@basealt.ru
Backpatch-through: 15
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/parser/gram.y | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 3c4268b271a..0b5652071d1 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -14230,7 +14230,7 @@ xmltable_column_el: parser_errposition(defel->location))); fc->colexpr = defel->arg; } - else if (strcmp(defel->defname, "is_not_null") == 0) + else if (strcmp(defel->defname, "__pg__is_not_null") == 0) { if (nullability_seen) ereport(ERROR, @@ -14273,13 +14273,20 @@ xmltable_column_option_list: xmltable_column_option_el: IDENT b_expr - { $$ = makeDefElem($1, $2, @1); } + { + if (strcmp($1, "__pg__is_not_null") == 0) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("option name \"%s\" cannot be used in XMLTABLE", $1), + parser_errposition(@1))); + $$ = makeDefElem($1, $2, @1); + } | DEFAULT b_expr { $$ = makeDefElem("default", $2, @1); } | NOT NULL_P - { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); } + { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); } | NULL_P - { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); } + { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); } | PATH b_expr { $$ = makeDefElem("path", $2, @1); } ; |