@@ -1281,6 +1281,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
12811281 options |= XML_PARSE_NOBLANKS ;
12821282 }
12831283
1284+ php_libxml_sanitize_parse_ctxt_options (ctxt );
12841285 xmlCtxtUseOptions (ctxt , options );
12851286
12861287 ctxt -> recovery = recover ;
@@ -1575,7 +1576,9 @@ PHP_METHOD(DOMDocument, xinclude)
15751576
15761577 DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
15771578
1579+ PHP_LIBXML_SANITIZE_GLOBALS (xinclude );
15781580 err = xmlXIncludeProcessFlags (docp , (int )flags );
1581+ PHP_LIBXML_RESTORE_GLOBALS (xinclude );
15791582
15801583 /* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
15811584 are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
@@ -1613,6 +1616,7 @@ PHP_METHOD(DOMDocument, validate)
16131616
16141617 DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
16151618
1619+ PHP_LIBXML_SANITIZE_GLOBALS (validate );
16161620 cvp = xmlNewValidCtxt ();
16171621
16181622 cvp -> userData = NULL ;
@@ -1624,6 +1628,7 @@ PHP_METHOD(DOMDocument, validate)
16241628 } else {
16251629 RETVAL_FALSE ;
16261630 }
1631+ PHP_LIBXML_RESTORE_GLOBALS (validate );
16271632
16281633 xmlFreeValidCtxt (cvp );
16291634
@@ -1658,14 +1663,18 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
16581663
16591664 DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
16601665
1666+ PHP_LIBXML_SANITIZE_GLOBALS (new_parser_ctxt );
1667+
16611668 switch (type ) {
16621669 case DOM_LOAD_FILE :
16631670 if (CHECK_NULL_PATH (source , source_len )) {
1671+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
16641672 zend_argument_value_error (1 , "must not contain any null bytes" );
16651673 RETURN_THROWS ();
16661674 }
16671675 valid_file = _dom_get_valid_file_path (source , resolved_path , MAXPATHLEN );
16681676 if (!valid_file ) {
1677+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
16691678 php_error_docref (NULL , E_WARNING , "Invalid Schema file source" );
16701679 RETURN_FALSE ;
16711680 }
@@ -1686,6 +1695,7 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
16861695 parser );
16871696 sptr = xmlSchemaParse (parser );
16881697 xmlSchemaFreeParserCtxt (parser );
1698+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
16891699 if (!sptr ) {
16901700 if (!EG (exception )) {
16911701 php_error_docref (NULL , E_WARNING , "Invalid Schema" );
@@ -1706,11 +1716,13 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
17061716 valid_opts |= XML_SCHEMA_VAL_VC_I_CREATE ;
17071717 }
17081718
1719+ PHP_LIBXML_SANITIZE_GLOBALS (validate );
17091720 xmlSchemaSetValidOptions (vptr , valid_opts );
17101721 xmlSchemaSetValidErrors (vptr , php_libxml_error_handler , php_libxml_error_handler , vptr );
17111722 is_valid = xmlSchemaValidateDoc (vptr , docp );
17121723 xmlSchemaFree (sptr );
17131724 xmlSchemaFreeValidCtxt (vptr );
1725+ PHP_LIBXML_RESTORE_GLOBALS (validate );
17141726
17151727 if (is_valid == 0 ) {
17161728 RETURN_TRUE ;
@@ -1781,12 +1793,14 @@ static void _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int typ
17811793 return ;
17821794 }
17831795
1796+ PHP_LIBXML_SANITIZE_GLOBALS (parse );
17841797 xmlRelaxNGSetParserErrors (parser ,
17851798 (xmlRelaxNGValidityErrorFunc ) php_libxml_error_handler ,
17861799 (xmlRelaxNGValidityWarningFunc ) php_libxml_error_handler ,
17871800 parser );
17881801 sptr = xmlRelaxNGParse (parser );
17891802 xmlRelaxNGFreeParserCtxt (parser );
1803+ PHP_LIBXML_RESTORE_GLOBALS (parse );
17901804 if (!sptr ) {
17911805 php_error_docref (NULL , E_WARNING , "Invalid RelaxNG" );
17921806 RETURN_FALSE ;
@@ -1885,6 +1899,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
18851899 ctxt -> sax -> error = php_libxml_ctx_error ;
18861900 ctxt -> sax -> warning = php_libxml_ctx_warning ;
18871901 }
1902+ php_libxml_sanitize_parse_ctxt_options (ctxt );
18881903 if (options ) {
18891904 htmlCtxtUseOptions (ctxt , (int )options );
18901905 }
0 commit comments