Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2f48b4f

Browse files
author
Richard Guo
committed
Fix Assert failure in XMLTABLE parser
In an XMLTABLE expression, columns can be marked NOT NULL, and theparser internally fabricates an option named "is_not_null" torepresent this. However, the parser also allows users to specifyarbitrary option names. This creates a conflict: a user canexplicitly use "is_not_null" as an option name and assign it anon-Boolean value, which violates internal assumptions and triggers anassertion failure.To fix, this patch checks whether a user-supplied name collides withthe internally reserved option name and raises an error if so.Additionally, the internal name is renamed to "__pg__is_not_null" tofurther 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.ruBackpatch-through: 15
1 parentc563919 commit2f48b4f

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
@@ -14048,7 +14048,7 @@ xmltable_column_el:
1404814048
parser_errposition(defel->location)));
1404914049
fc->colexpr = defel->arg;
1405014050
}
14051-
elseif (strcmp(defel->defname,"is_not_null") ==0)
14051+
elseif (strcmp(defel->defname,"__pg__is_not_null") ==0)
1405214052
{
1405314053
if (nullability_seen)
1405414054
ereport(ERROR,
@@ -14091,13 +14091,20 @@ xmltable_column_option_list:
1409114091

1409214092
xmltable_column_option_el:
1409314093
IDENTb_expr
14094-
{$$ = makeDefElem($1,$2,@1); }
14094+
{
14095+
if (strcmp($1,"__pg__is_not_null") ==0)
14096+
ereport(ERROR,
14097+
(errcode(ERRCODE_SYNTAX_ERROR),
14098+
errmsg("option name\"%s\" cannot be used in XMLTABLE", $1),
14099+
parser_errposition(@1)));
14100+
$$ = makeDefElem($1,$2,@1);
14101+
}
1409514102
|DEFAULTb_expr
1409614103
{$$ = makeDefElem("default",$2,@1); }
1409714104
|NOTNULL_P
14098-
{$$ = makeDefElem("is_not_null", (Node *) makeBoolean(true),@1); }
14105+
{$$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true),@1); }
1409914106
|NULL_P
14100-
{$$ = makeDefElem("is_not_null", (Node *) makeBoolean(false),@1); }
14107+
{$$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false),@1); }
1410114108
|PATHb_expr
1410214109
{$$ = makeDefElem("path",$2,@1); }
1410314110
;

‎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 () PASSINGnull COLUMNS v1timestamp)AS f (v1, v2);
437437

438+
SELECT*FROM XMLTABLE (ROW () PASSINGnull COLUMNS v1timestamp __pg__is_not_null1)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)

[8]ページ先頭

©2009-2025 Movatter.jp