mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +03:00
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 commit251cf2e27
fixed this, somewhat accidentally, in v12. We're not going to back-patch251cf2e27
, 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)
This commit is contained in:
@@ -4612,6 +4612,12 @@ XmlTableGetValue(TableFuncScanState *state, int colnum,
|
||||
xmlChar *str;
|
||||
xmlNodePtr node;
|
||||
|
||||
node = xpathobj->nodesetval->nodeTab[0];
|
||||
if (node->type == XML_NAMESPACE_DECL)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("XMLTABLE cannot cast a namespace node to a non-XML result type")));
|
||||
|
||||
/*
|
||||
* Most nodes (elements and even attributes) store their data
|
||||
* in children nodes. If they don't have children nodes, it
|
||||
@@ -4619,7 +4625,6 @@ XmlTableGetValue(TableFuncScanState *state, int colnum,
|
||||
* CDATA sections are an exception: they don't have children
|
||||
* but have content in the Text/CDATA node itself.
|
||||
*/
|
||||
node = xpathobj->nodesetval->nodeTab[0];
|
||||
if (node->type != XML_CDATA_SECTION_NODE &&
|
||||
node->type != XML_TEXT_NODE)
|
||||
node = node->xmlChildrenNode;
|
||||
|
Reference in New Issue
Block a user