Content-Length: 420053 | pFad | http://github.com/postgres/postgres/commit/d3716d4b135756e38775a29a5ca26e17bd0efafc

17 Fix Assert failure in XMLTABLE parser · postgres/postgres@d3716d4 · GitHub
Skip to content

Commit d3716d4

Browse files
author
Richard Guo
committed
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
1 parent 9c94d98 commit d3716d4

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

src/backend/parser/gram.y

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13838,7 +13838,7 @@ xmltable_column_el:
1383813838
parser_errposition(defel->location)));
1383913839
fc->colexpr = defel->arg;
1384013840
}
13841-
else if (strcmp(defel->defname, "is_not_null") == 0)
13841+
else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
1384213842
{
1384313843
if (nullability_seen)
1384413844
ereport(ERROR,
@@ -13881,13 +13881,20 @@ xmltable_column_option_list:
1388113881

1388213882
xmltable_column_option_el:
1388313883
IDENT b_expr
13884-
{ $$ = makeDefElem($1, $2, @1); }
13884+
{
13885+
if (strcmp($1, "__pg__is_not_null") == 0)
13886+
ereport(ERROR,
13887+
(errcode(ERRCODE_SYNTAX_ERROR),
13888+
errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
13889+
parser_errposition(@1)));
13890+
$$ = makeDefElem($1, $2, @1);
13891+
}
1388513892
| DEFAULT b_expr
1388613893
{ $$ = makeDefElem("default", $2, @1); }
1388713894
| NOT NULL_P
13888-
{ $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
13895+
{ $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
1388913896
| NULL_P
13890-
{ $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
13897+
{ $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
1389113898
;
1389213899

1389313900
xml_namespace_list:

src/test/regress/expected/xml.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,10 @@ EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM xmltableview1;
13731373
-- errors
13741374
SELECT * FROM XMLTABLE (ROW () PASSING null COLUMNS v1 timestamp) AS f (v1, v2);
13751375
ERROR: XMLTABLE function has 1 columns available but 2 columns specified
1376+
SELECT * FROM XMLTABLE (ROW () PASSING null COLUMNS v1 timestamp __pg__is_not_null 1) AS f (v1);
1377+
ERROR: option name "__pg__is_not_null" cannot be used in XMLTABLE
1378+
LINE 1: ...MLTABLE (ROW () PASSING null COLUMNS v1 timestamp __pg__is_n...
1379+
^
13761380
-- XMLNAMESPACES tests
13771381
SELECT * FROM XMLTABLE(XMLNAMESPACES('http://x.y' AS zz),
13781382
'/zz:rows/zz:row'

src/test/regress/expected/xml_1.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,10 @@ EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM xmltableview1;
10471047
-- errors
10481048
SELECT * FROM XMLTABLE (ROW () PASSING null COLUMNS v1 timestamp) AS f (v1, v2);
10491049
ERROR: XMLTABLE function has 1 columns available but 2 columns specified
1050+
SELECT * FROM XMLTABLE (ROW () PASSING null COLUMNS v1 timestamp __pg__is_not_null 1) AS f (v1);
1051+
ERROR: option name "__pg__is_not_null" cannot be used in XMLTABLE
1052+
LINE 1: ...MLTABLE (ROW () PASSING null COLUMNS v1 timestamp __pg__is_n...
1053+
^
10501054
-- XMLNAMESPACES tests
10511055
SELECT * FROM XMLTABLE(XMLNAMESPACES('http://x.y' AS zz),
10521056
'/zz:rows/zz:row'

src/test/regress/expected/xml_2.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,10 @@ EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM xmltableview1;
13591359
-- errors
13601360
SELECT * FROM XMLTABLE (ROW () PASSING null COLUMNS v1 timestamp) AS f (v1, v2);
13611361
ERROR: XMLTABLE function has 1 columns available but 2 columns specified
1362+
SELECT * FROM XMLTABLE (ROW () PASSING null COLUMNS v1 timestamp __pg__is_not_null 1) AS f (v1);
1363+
ERROR: option name "__pg__is_not_null" cannot be used in XMLTABLE
1364+
LINE 1: ...MLTABLE (ROW () PASSING null COLUMNS v1 timestamp __pg__is_n...
1365+
^
13621366
-- XMLNAMESPACES tests
13631367
SELECT * FROM XMLTABLE(XMLNAMESPACES('http://x.y' AS zz),
13641368
'/zz:rows/zz:row'

src/test/regress/sql/xml.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM xmltableview1;
435435
-- errors
436436
SELECT * FROM XMLTABLE (ROW () PASSING null COLUMNS v1 timestamp) AS f (v1, v2);
437437

438+
SELECT * FROM XMLTABLE (ROW () PASSING null COLUMNS v1 timestamp __pg__is_not_null 1) AS f (v1);
439+
438440
-- XMLNAMESPACES tests
439441
SELECT * FROM XMLTABLE(XMLNAMESPACES('http://x.y' AS zz),
440442
'/zz:rows/zz:row'

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgres/postgres/commit/d3716d4b135756e38775a29a5ca26e17bd0efafc

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy