Skip to content

Commit 106079a

Browse files
committed
dom: Switch to new safe option setting API
This API does not suffer from the global issue and does therefore not require a sanitization fixup. The API for XML is available starting from libxml 2.13, the one for HTML since 2.14.
1 parent 571f119 commit 106079a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ext/dom/document.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,12 @@ xmlDocPtr dom_document_parser(zval *id, dom_load_mode mode, const char *source,
14481448
options |= XML_PARSE_RECOVER;
14491449
}
14501450

1451+
#if LIBXML_VERSION >= 21300
1452+
xmlCtxtSetOptions(ctxt, options);
1453+
#else
14511454
php_libxml_sanitize_parse_ctxt_options(ctxt);
14521455
xmlCtxtUseOptions(ctxt, options);
1456+
#endif
14531457

14541458
if (recover) {
14551459
old_error_reporting = EG(error_reporting);
@@ -2086,10 +2090,16 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
20862090
ctxt->sax->error = php_libxml_ctx_error;
20872091
ctxt->sax->warning = php_libxml_ctx_warning;
20882092
}
2093+
#if LIBXML_VERSION >= 21400
2094+
if (options) {
2095+
htmlCtxtSetOptions(ctxt, (int)options);
2096+
}
2097+
#else
20892098
php_libxml_sanitize_parse_ctxt_options(ctxt);
20902099
if (options) {
20912100
htmlCtxtUseOptions(ctxt, (int)options);
20922101
}
2102+
#endif
20932103
htmlParseDocument(ctxt);
20942104
xmlDocPtr newdoc = ctxt->myDoc;
20952105
htmlFreeParserCtxt(ctxt);

ext/dom/inner_outer_html_mixin.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,12 @@ static xmlNodePtr dom_xml_fragment_parsing_algorithm(dom_object *obj, const xmlN
291291
}
292292
parser->dict = context_node->doc->dict;
293293

294+
#if LIBXML_VERSION >= 21300
295+
xmlCtxtSetOptions(parser, XML_PARSE_IGNORE_ENC | XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NO_XXE);
296+
#else
294297
php_libxml_sanitize_parse_ctxt_options(parser);
295298
xmlCtxtUseOptions(parser, XML_PARSE_IGNORE_ENC | XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
299+
#endif
296300

297301
xmlCharEncodingHandlerPtr encoding = xmlFindCharEncodingHandler("UTF-8");
298302
(void) xmlSwitchToEncoding(parser, encoding);

0 commit comments

Comments
 (0)