mirror of
https://github.com/postgres/postgres.git
synced 2026-06-15 11:39:05 -04:00
xml2: Fix crash with namespace nodes in xpath_nodeset()
pgxmlNodeSetToText() passed nodeTab[i]->doc to xmlNodeDump() without checking the node type, which could cause a crash as a XML_NAMESPACE_DECL maps to a xmlNs struct. The passed-in code would then be dereferenced in xmlNodeDump(). This commit switches the code to render XML_NAMESPACE_DECL nodes with xmlXPathCastNodeToString(), like xpath_table(). Some tests are added, written by me. Author: Andrey Chernyy <andrey.cherny@tantorlabs.com> Co-authored-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/20260611031436.5afde3cb@andrnote Backpatch-through: 14
This commit is contained in:
parent
beb09e9117
commit
91b57eadeb
4 changed files with 30 additions and 4 deletions
|
|
@ -231,6 +231,14 @@ SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
|
|||
<result><item><author>test</author></item><item><pages>37</pages></item></result>
|
||||
(1 row)
|
||||
|
||||
-- namespace node
|
||||
SELECT xpath_nodeset('<root xmlns:foo="http://icl.com/saxon"/>',
|
||||
'//namespace::foo');
|
||||
xpath_nodeset
|
||||
----------------------
|
||||
http://icl.com/saxon
|
||||
(1 row)
|
||||
|
||||
-- xpath_list()
|
||||
SELECT xpath_list(article_xml::text, '/article/author|/article/pages')
|
||||
FROM articles;
|
||||
|
|
|
|||
|
|
@ -175,6 +175,14 @@ SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
|
|||
<result><item><author>test</author></item><item><pages>37</pages></item></result>
|
||||
(1 row)
|
||||
|
||||
-- namespace node
|
||||
SELECT xpath_nodeset('<root xmlns:foo="http://icl.com/saxon"/>',
|
||||
'//namespace::foo');
|
||||
xpath_nodeset
|
||||
----------------------
|
||||
http://icl.com/saxon
|
||||
(1 row)
|
||||
|
||||
-- xpath_list()
|
||||
SELECT xpath_list(article_xml::text, '/article/author|/article/pages')
|
||||
FROM articles;
|
||||
|
|
|
|||
|
|
@ -132,6 +132,9 @@ SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
|
|||
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
|
||||
'result', 'item')
|
||||
FROM articles;
|
||||
-- namespace node
|
||||
SELECT xpath_nodeset('<root xmlns:foo="http://icl.com/saxon"/>',
|
||||
'//namespace::foo');
|
||||
|
||||
-- xpath_list()
|
||||
SELECT xpath_list(article_xml::text, '/article/author|/article/pages')
|
||||
|
|
|
|||
|
|
@ -149,16 +149,23 @@ pgxmlNodeSetToText(xmlNodeSetPtr nodeset,
|
|||
}
|
||||
else
|
||||
{
|
||||
xmlNodePtr node = nodeset->nodeTab[i];
|
||||
|
||||
if ((septagname != NULL) && (xmlStrlen(septagname) > 0))
|
||||
{
|
||||
xmlBufferWriteChar(buf, "<");
|
||||
xmlBufferWriteCHAR(buf, septagname);
|
||||
xmlBufferWriteChar(buf, ">");
|
||||
}
|
||||
xmlNodeDump(buf,
|
||||
nodeset->nodeTab[i]->doc,
|
||||
nodeset->nodeTab[i],
|
||||
1, 0);
|
||||
|
||||
/*
|
||||
* XML_NAMESPACE_DECL nodes are xmlNs structs, that cannot
|
||||
* be processed by xmlNodeDump().
|
||||
*/
|
||||
if (node->type == XML_NAMESPACE_DECL)
|
||||
xmlBufferWriteCHAR(buf, xmlXPathCastNodeToString(node));
|
||||
else
|
||||
xmlNodeDump(buf, node->doc, node, 1, 0);
|
||||
|
||||
if ((septagname != NULL) && (xmlStrlen(septagname) > 0))
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue