Skip to content
Snippets Groups Projects

main/libxml2: upgrade to 2.13.5

Closed J0WI requested to merge J0WI/aports:libxml2-2.13.5 into master
1 unresolved thread
2 files
+ 4
121
Compare changes
  • Side-by-side
  • Inline
Files
2
From 551e925cf11d56269b0a1c8e6f58cc855d8b4757 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Wed, 30 Oct 2024 14:02:36 +0100
Subject: [PATCH] parser: Fix downstream code that swaps DTDs
Downstream code like the nginx xslt module can change the document's DTD
pointers in a SAX callback. If an entity from a separate DTD is parsed
lazily, its content must not reference the current document.
Regressed with commit d025cfbb.
Fixes #815.
(cherry picked from commit efb57ddba3571928395644568444990e8ea831ea)
---
parser.c | 9 +++++++++
testparser.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/parser.c b/parser.c
index 365025c5..82982a7a 100644
--- a/parser.c
+++ b/parser.c
@@ -12143,6 +12143,15 @@ xmlCtxtParseEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr ent) {
while (list != NULL) {
list->parent = (xmlNodePtr) ent;
+
+ /*
+ * Downstream code like the nginx xslt module can set
+ * ctxt->myDoc->extSubset to a separate DTD, so the entity
+ * might have a different or a NULL document.
+ */
+ if (list->doc != ent->doc)
+ xmlSetTreeDoc(list, ent->doc);
+
if (list->next == NULL)
ent->last = list;
list = list->next;
diff --git a/testparser.c b/testparser.c
index 1f8e58c4..342f6250 100644
--- a/testparser.c
+++ b/testparser.c
@@ -125,6 +125,57 @@ testCFileIO(void) {
return err;
}
+#ifdef LIBXML_VALID_ENABLED
+static void
+testSwitchDtdExtSubset(void *vctxt, const xmlChar *name ATTRIBUTE_UNUSED,
+ const xmlChar *externalId ATTRIBUTE_UNUSED,
+ const xmlChar *systemId ATTRIBUTE_UNUSED) {
+ xmlParserCtxtPtr ctxt = vctxt;
+
+ ctxt->myDoc->extSubset = ctxt->_private;
+}
+
+static int
+testSwitchDtd(void) {
+ const char dtdContent[] =
+ "<!ENTITY test '<elem1/><elem2/>'>\n";
+ const char docContent[] =
+ "<!DOCTYPE doc SYSTEM 'entities.dtd'>\n"
+ "<doc>&test;</doc>\n";
+ xmlParserInputBufferPtr input;
+ xmlParserCtxtPtr ctxt;
+ xmlDtdPtr dtd;
+ xmlDocPtr doc;
+ xmlEntityPtr ent;
+ int err = 0;
+
+ input = xmlParserInputBufferCreateStatic(dtdContent,
+ sizeof(dtdContent) - 1,
+ XML_CHAR_ENCODING_NONE);
+ dtd = xmlIOParseDTD(NULL, input, XML_CHAR_ENCODING_NONE);
+
+ ctxt = xmlNewParserCtxt();
+ ctxt->_private = dtd;
+ ctxt->sax->externalSubset = testSwitchDtdExtSubset;
+ doc = xmlCtxtReadMemory(ctxt, docContent, sizeof(docContent) - 1, NULL,
+ NULL, XML_PARSE_NOENT | XML_PARSE_DTDLOAD);
+ xmlFreeParserCtxt(ctxt);
+
+ ent = xmlGetDocEntity(doc, BAD_CAST "test");
+ if (ent->children->doc != NULL) {
+ fprintf(stderr, "Entity content should have NULL doc\n");
+ err = 1;
+ }
+
+ /* Free doc before DTD */
+ doc->extSubset = NULL;
+ xmlFreeDoc(doc);
+ xmlFreeDtd(dtd);
+
+ return err;
+}
+#endif /* LIBXML_VALID_ENABLED */
+
#ifdef LIBXML_SAX1_ENABLED
static int
testBalancedChunk(void) {
@@ -571,6 +622,9 @@ main(void) {
err |= testUnsupportedEncoding();
err |= testNodeGetContent();
err |= testCFileIO();
+#ifdef LIBXML_VALID_ENABLED
+ err |= testSwitchDtd();
+#endif
#ifdef LIBXML_SAX1_ENABLED
err |= testBalancedChunk();
#endif
--
2.46.2
Loading