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

Commit9f7a664

Browse files
committed
Avoid failure when selecting a namespace node in XMLTABLE.
It appears that libxml2 doesn't bother to set the "children" field ofan XML_NAMESPACE_DECL node to null; that field just contains garbage.In v10 and v11, this can result in a crash in XMLTABLE(). The rewritedone in commit251cf2e fixed this, somewhat accidentally, in v12.We're not going to back-patch251cf2e, however. The case apparentlydoesn't have wide use, so rather than risk introducing other problems,just add a safety check to throw an error.Even though no bug manifests in v12/HEAD, add the relevant test casethere too, to prevent future regressions.Chapman Flack (per private report)
1 parent2930f16 commit9f7a664

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

‎src/backend/utils/adt/xml.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4612,14 +4612,19 @@ XmlTableGetValue(TableFuncScanState *state, int colnum,
46124612
xmlChar*str;
46134613
xmlNodePtrnode;
46144614

4615+
node=xpathobj->nodesetval->nodeTab[0];
4616+
if (node->type==XML_NAMESPACE_DECL)
4617+
ereport(ERROR,
4618+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4619+
errmsg("XMLTABLE cannot cast a namespace node to a non-XML result type")));
4620+
46154621
/*
46164622
* Most nodes (elements and even attributes) store their data
46174623
* in children nodes. If they don't have children nodes, it
46184624
* means that they are empty (e.g. <element/>). Text nodes and
46194625
* CDATA sections are an exception: they don't have children
46204626
* but have content in the Text/CDATA node itself.
46214627
*/
4622-
node=xpathobj->nodesetval->nodeTab[0];
46234628
if (node->type!=XML_CDATA_SECTION_NODE&&
46244629
node->type!=XML_TEXT_NODE)
46254630
node=node->xmlChildrenNode;

‎src/test/regress/expected/xml.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,10 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'),
11731173
PASSING '<rows xmlns="http://x.y"><row><a>10</a></row></rows>'
11741174
COLUMNS a int PATH 'a');
11751175
ERROR: DEFAULT namespace is not supported
1176+
SELECT * FROM XMLTABLE('.'
1177+
PASSING '<foo/>'
1178+
COLUMNS a text PATH 'foo/namespace::node()');
1179+
ERROR: XMLTABLE cannot cast a namespace node to a non-XML result type
11761180
-- used in prepare statements
11771181
PREPARE pp AS
11781182
SELECT xmltable.*

‎src/test/regress/expected/xml_1.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,14 @@ LINE 3: PASSING '<rows xmlns="http://x.y"><row...
10481048
^
10491049
DETAIL: This functionality requires the server to be built with libxml support.
10501050
HINT: You need to rebuild PostgreSQL using --with-libxml.
1051+
SELECT * FROM XMLTABLE('.'
1052+
PASSING '<foo/>'
1053+
COLUMNS a text PATH 'foo/namespace::node()');
1054+
ERROR: unsupported XML feature
1055+
LINE 2: PASSING '<foo/>'
1056+
^
1057+
DETAIL: This functionality requires the server to be built with libxml support.
1058+
HINT: You need to rebuild PostgreSQL using --with-libxml.
10511059
-- used in prepare statements
10521060
PREPARE pp AS
10531061
SELECT xmltable.*

‎src/test/regress/expected/xml_2.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,10 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'),
11531153
PASSING '<rows xmlns="http://x.y"><row><a>10</a></row></rows>'
11541154
COLUMNS a int PATH 'a');
11551155
ERROR: DEFAULT namespace is not supported
1156+
SELECT * FROM XMLTABLE('.'
1157+
PASSING '<foo/>'
1158+
COLUMNS a text PATH 'foo/namespace::node()');
1159+
ERROR: XMLTABLE cannot cast a namespace node to a non-XML result type
11561160
-- used in prepare statements
11571161
PREPARE pp AS
11581162
SELECT xmltable.*

‎src/test/regress/sql/xml.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'),
402402
PASSING'<rows xmlns="http://x.y"><row><a>10</a></row></rows>'
403403
COLUMNS aintPATH'a');
404404

405+
SELECT*FROM XMLTABLE('.'
406+
PASSING'<foo/>'
407+
COLUMNS atextPATH'foo/namespace::node()');
408+
405409
-- used in prepare statements
406410
PREPARE ppAS
407411
SELECT xmltable.*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp