1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

parser: Don't modify SAX2 handler if XML_PARSE_SAX1 is set

It's a bad idea to modify members of the SAX handler struct for option
state management. Ideally, ctxt->options should be the preferred source
of truth.
This commit is contained in:
Nick Wellnhofer
2023-09-06 22:15:20 +02:00
parent 37c6618be5
commit 22fd571f3c

View File

@@ -950,7 +950,9 @@ xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
* Only enable SAX2 if there SAX2 element handlers, except when there
* are no element handlers at all.
*/
if ((sax) && (sax->initialized == XML_SAX2_MAGIC) &&
if (((ctxt->options & XML_PARSE_SAX1) == 0) &&
(sax) &&
(sax->initialized == XML_SAX2_MAGIC) &&
((sax->startElementNs != NULL) ||
(sax->endElementNs != NULL) ||
((sax->startElement == NULL) && (sax->endElement == NULL))))
@@ -13412,9 +13414,6 @@ xmlCtxtUseOptions(xmlParserCtxtPtr ctxt, int options)
}
#ifdef LIBXML_SAX1_ENABLED
if (options & XML_PARSE_SAX1) {
ctxt->sax->startElementNs = NULL;
ctxt->sax->endElementNs = NULL;
ctxt->sax->initialized = 1;
options -= XML_PARSE_SAX1;
ctxt->options |= XML_PARSE_SAX1;
}