• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 235b15a590eecf97b09e87bdb7e4f8333e9de129 Mon Sep 17 00:00:00 2001
2From: Nick Wellnhofer <wellnhofer@aevum.de>
3Date: Mon, 8 May 2023 17:58:02 +0200
4Subject: [PATCH] SAX: Always initialize SAX1 element handlers
5
6Follow-up to commit d0c3f01e. A parser context will be initialized to
7SAX version 2, but this can be overridden with XML_PARSE_SAX1 later,
8so we must initialize the SAX1 element handlers as well.
9
10Change the check in xmlDetectSAX2 to only look for XML_SAX2_MAGIC, so
11we don't switch to SAX1 if the SAX2 element handlers are NULL.
12---
13 SAX2.c   | 11 +++++++----
14 parser.c |  5 +----
15 2 files changed, 8 insertions(+), 8 deletions(-)
16
17diff --git a/SAX2.c b/SAX2.c
18index b6be1a6c4..910193892 100644
19--- a/SAX2.c
20+++ b/SAX2.c
21@@ -2874,20 +2874,23 @@ xmlSAXVersion(xmlSAXHandler *hdlr, int version)
22 {
23     if (hdlr == NULL) return(-1);
24     if (version == 2) {
25-	hdlr->startElement = NULL;
26-	hdlr->endElement = NULL;
27 	hdlr->startElementNs = xmlSAX2StartElementNs;
28 	hdlr->endElementNs = xmlSAX2EndElementNs;
29 	hdlr->serror = NULL;
30 	hdlr->initialized = XML_SAX2_MAGIC;
31 #ifdef LIBXML_SAX1_ENABLED
32     } else if (version == 1) {
33-	hdlr->startElement = xmlSAX2StartElement;
34-	hdlr->endElement = xmlSAX2EndElement;
35 	hdlr->initialized = 1;
36 #endif /* LIBXML_SAX1_ENABLED */
37     } else
38         return(-1);
39+#ifdef LIBXML_SAX1_ENABLED
40+    hdlr->startElement = xmlSAX2StartElement;
41+    hdlr->endElement = xmlSAX2EndElement;
42+#else
43+    hdlr->startElement = NULL;
44+    hdlr->endElement = NULL;
45+#endif /* LIBXML_SAX1_ENABLED */
46     hdlr->internalSubset = xmlSAX2InternalSubset;
47     hdlr->externalSubset = xmlSAX2ExternalSubset;
48     hdlr->isStandalone = xmlSAX2IsStandalone;
49diff --git a/parser.c b/parser.c
50index 0c8bed129..e133fe0a6 100644
51--- a/parser.c
52+++ b/parser.c
53@@ -842,10 +842,7 @@ xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
54     if (ctxt == NULL) return;
55     sax = ctxt->sax;
56 #ifdef LIBXML_SAX1_ENABLED
57-    if ((sax) &&  (sax->initialized == XML_SAX2_MAGIC) &&
58-        ((sax->startElementNs != NULL) ||
59-         (sax->endElementNs != NULL) ||
60-         ((sax->startElement == NULL) && (sax->endElement == NULL))))
61+    if ((sax) && (sax->initialized == XML_SAX2_MAGIC))
62         ctxt->sax2 = 1;
63 #else
64     ctxt->sax2 = 1;
65--
66GitLab
67
68