From c3c7ba8737a30badc9d2ab44c486a952a05f0c68 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Tue, 13 Oct 2026 09:45:38 -0300 Subject: [PATCH] fix: silence libxml2 parser errors on every libxml2 version Since 3.0.15 (b9dc9cc8) the XML body processor sets XML_PARSE_NOERROR and XML_PARSE_NOWARNING by OR-ing them into ctxt->options directly. libxml2 only honours options stored that way from 2.13 on; older releases (2.9 through 2.12, e.g. Amazon Linux 2023, Ubuntu 22.04, RHEL 9) apply the flags inside xmlCtxtUseOptions() by clearing the SAX error callbacks, so the direct assignment is a no-op and every malformed body prints "body.xml:1: parser error : ..." to stderr, which nginx forwards to its error log without a timestamp prefix. 3.0.14 did not show this because it still called xmlSetGenericErrorFunc() with a null handler, which 624a0dee removed as deprecated. Call xmlCtxtUseOptions() instead, which works on both old and new libxml2 and is not deprecated. Verified with a push-parser test program against libxml2 2.9.13 and 2.15.4, and with the existing variable-REQBODY_PROCESSOR_ERROR regression test, whose stderr output goes from one parser error line to none. Fixes #3563 Co-Authored-By: Claude Fable 5.1 --- src/request_body_processor/xml.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/request_body_processor/xml.cc b/src/request_body_processor/xml.cc index db3f74d6d..6003e3989 100644 --- a/src/request_body_processor/xml.cc +++ b/src/request_body_processor/xml.cc @@ -252,7 +252,7 @@ bool XML::processChunk(const char *buf, unsigned int size, return false; } // disable parser errors being printed to stderr - m_data.parsing_ctx->options |= XML_PARSE_NOWARNING | XML_PARSE_NOERROR; + xmlCtxtUseOptions(m_data.parsing_ctx, XML_PARSE_NOWARNING | XML_PARSE_NOERROR); } if (m_transaction->m_secXMLParseXmlIntoArgs @@ -270,7 +270,7 @@ bool XML::processChunk(const char *buf, unsigned int size, return false; } // disable parser errors being printed to stderr - m_data.parsing_ctx_arg->options |= XML_PARSE_NOWARNING | XML_PARSE_NOERROR; + xmlCtxtUseOptions(m_data.parsing_ctx_arg, XML_PARSE_NOWARNING | XML_PARSE_NOERROR); // the SAX callback (onEndElement) stops parsing through this // context when SecArgumentsLimit is hit; it must be set here, // not only in the multi-chunk branch below.