xml2: Fix crash with namespace nodes in xpath_nodeset()

Michael Paquier <michael@paquier.xyz>

Commit: 18955d412c8228fbb1f1982ea0d6231dae7d9611
Author: Michael Paquier <michael@paquier.xyz>
Date: 2026-06-11T05:29:26Z
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

Files

PathChange+/−
contrib/xml2/expected/xml2_1.out modified +8 −0
contrib/xml2/expected/xml2.out modified +8 −0
contrib/xml2/sql/xml2.sql modified +4 −0
contrib/xml2/xpath.c modified +11 −4

Discussion