Re: BUG #18943: Return value of a function 'xmlBufferCreate' isdereferenced at xpath.c:177 without checking for NUL
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Alexander Lakhin <exclusion@gmail.com>
Cc: cca5507 <cca5507@qq.com>, Jim Jones <jim.jones@uni-muenster.de>, Tom Lane <tgl@sss.pgh.pa.us>, pgsql-bugs <pgsql-bugs@lists.postgresql.org>, maralist86 <maralist86@mail.ru>
Date: 2026-03-12T06:46:57Z
Lists: pgsql-bugs
Attachments
- 0001-xml2-Fix-undeterministic-result-with-xslt_process.patch (text/plain) patch 0001
On Thu, Mar 12, 2026 at 07:00:00AM +0200, Alexander Lakhin wrote:
> Hello Michael,
>
> Maybe you would like to fix in passing one more anomaly there:
> create extension xml2;
> select xslt_process('<aaa/>','<xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"></xsl:stylesheet>');
>
> leads to:
> varlena.c:199:2: runtime error: null pointer passed as argument 2, which is declared to never be null
> #0 0x640756666936 in cstring_to_text_with_len .../src/backend/utils/adt/varlena.c:199
> #1 0x7e46c0f4805e in xslt_process .../contrib/xml2/xslt_proc.c:149
> #2 0x640755a3ecbf in ExecInterpExpr .../src/backend/executor/execExprInterp.c:1001
> #3 0x640755a277aa in ExecInterpExprStillValid .../src/backend/executor/execExprInterp.c:2299
> #4 0x640755ef11e0 in ExecEvalExprSwitchContext ../../../../src/include/executor/executor.h:444
> #5 0x640755efd7b6 in evaluate_expr .../src/backend/optimizer/util/clauses.c:5724
>
> for a build made with -fsanitize=undefined.
Indeed, I can reproduce it locally. This one is a super old
inconsistency, from what I can see. This predates the introduction to
xml2 in contrib and even the use of cstring_to_text_with_len(). We've
never thought that xsltSaveResultToString() could return a NULL
xmlChar with a valid status code and a length of 0. Back in the
day, before cstring_to_text_with_len(), that would be a memcpy with a
NULL pointer.
I am not sure if this is worth backpatching, so let's just use
something like the attached on HEAD. This result cannot be NULL,
historically it has always been an empty string.
Opinions?
--
Michael
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
xml2: Fix failure with xslt_process() under -fsanitize=undefined
- 70f7c5badcc0 14.23 landed
- 0b0041b942f7 15.18 landed
- 5f46c617e95f 16.14 landed
- 63aa4342da23 17.10 landed
- e33a4fda0027 18.4 landed
- 7d64419f8073 19 (unreleased) landed
-
Fix misuse of "volatile" in xml.c
- 6307b096e259 19 (unreleased) landed
-
xml2: Improve error handling of libxml2 calls
- 732061150b00 19 (unreleased) landed
-
Improve error handling of libxml2 calls in xml.c
- 2e947217474c 19 (unreleased) landed