From 2bbdf8e2e827fe80fd39a4a5e2f432f4e8ae6ca3 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 25 Oct 2019 15:22:40 -0400 Subject: [PATCH] Avoid failure when selecting a namespace node in XMLTABLE. It appears that libxml2 doesn't bother to set the "children" field of an XML_NAMESPACE_DECL node to null; that field just contains garbage. In v10 and v11, this can result in a crash in XMLTABLE(). The rewrite done in commit 251cf2e27 fixed this, somewhat accidentally, in v12. We're not going to back-patch 251cf2e27, however. The case apparently doesn'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 case there too, to prevent future regressions. Chapman Flack (per private report) --- src/test/regress/expected/xml.out | 8 ++++++++ src/test/regress/expected/xml_1.out | 8 ++++++++ src/test/regress/expected/xml_2.out | 8 ++++++++ src/test/regress/sql/xml.sql | 4 ++++ 4 files changed, 28 insertions(+) diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out index 11e7d7faf3..55b65ef324 100644 --- a/src/test/regress/expected/xml.out +++ b/src/test/regress/expected/xml.out @@ -1170,6 +1170,14 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'), PASSING '10' COLUMNS a int PATH 'a'); ERROR: DEFAULT namespace is not supported +SELECT * FROM XMLTABLE('.' + PASSING '' + COLUMNS a text PATH 'foo/namespace::node()'); + a +-------------------------------------- + http://www.w3.org/XML/1998/namespace +(1 row) + -- used in prepare statements PREPARE pp AS SELECT xmltable.* diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out index d1a03b51a3..ec6457875f 100644 --- a/src/test/regress/expected/xml_1.out +++ b/src/test/regress/expected/xml_1.out @@ -1048,6 +1048,14 @@ LINE 3: PASSING '' + COLUMNS a text PATH 'foo/namespace::node()'); +ERROR: unsupported XML feature +LINE 2: PASSING '' + ^ +DETAIL: This functionality requires the server to be built with libxml support. +HINT: You need to rebuild PostgreSQL using --with-libxml. -- used in prepare statements PREPARE pp AS SELECT xmltable.* diff --git a/src/test/regress/expected/xml_2.out b/src/test/regress/expected/xml_2.out index 4d20027469..0484260281 100644 --- a/src/test/regress/expected/xml_2.out +++ b/src/test/regress/expected/xml_2.out @@ -1150,6 +1150,14 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'), PASSING '10' COLUMNS a int PATH 'a'); ERROR: DEFAULT namespace is not supported +SELECT * FROM XMLTABLE('.' + PASSING '' + COLUMNS a text PATH 'foo/namespace::node()'); + a +-------------------------------------- + http://www.w3.org/XML/1998/namespace +(1 row) + -- used in prepare statements PREPARE pp AS SELECT xmltable.* diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index 71431d8a55..f3f83c7827 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -402,6 +402,10 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'), PASSING '10' COLUMNS a int PATH 'a'); +SELECT * FROM XMLTABLE('.' + PASSING '' + COLUMNS a text PATH 'foo/namespace::node()'); + -- used in prepare statements PREPARE pp AS SELECT xmltable.*