pgsql: xml2: Fix crash with namespace nodes in xpath_nodeset()

Started by Michael Paquier13 days ago1 messagescomitters
Jump to latest
#1Michael Paquier
michael@paquier.xyz

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: /messages/by-id/20260611031436.5afde3cb@andrnote
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f3f901a53a17da5c4f21c1df628d187b6aff1889

Modified Files
--------------
contrib/xml2/expected/xml2.out | 8 ++++++++
contrib/xml2/expected/xml2_1.out | 8 ++++++++
contrib/xml2/sql/xml2.sql | 4 ++++
contrib/xml2/xpath.c | 15 +++++++++++----
4 files changed, 31 insertions(+), 4 deletions(-)