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

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: xml2: Fix crash with namespace nodes in xpath_nodeset()
Date: 2026-06-11 05:29:48
Message-ID: E1wXXzA-001xcX-1F@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)cherny(at)tantorlabs(dot)com>
Co-authored-by: Michael Paquier <michael(at)paquier(dot)xyz>
Discussion: https://postgr.es/m/20260611031436.5afde3cb@andrnote
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9d33a5a804db48b254de7a0ad2fde03152f378e3

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

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-06-11 05:44:54 pgsql: Backport GetWALInsertionTimeLineIfSet()
Previous Message Tom Lane 2026-06-10 21:01:50 pgsql: Undo thinko in commit e78d1d6d4.