@@ -1285,6 +1285,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
12851285 options |= XML_PARSE_NOBLANKS ;
12861286 }
12871287
1288+ php_libxml_sanitize_parse_ctxt_options (ctxt );
12881289 xmlCtxtUseOptions (ctxt , options );
12891290
12901291 ctxt -> recovery = recover ;
@@ -1594,7 +1595,9 @@ PHP_METHOD(DOMDocument, xinclude)
15941595
15951596 DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
15961597
1598+ PHP_LIBXML_SANITIZE_GLOBALS (xinclude );
15971599 err = xmlXIncludeProcessFlags (docp , (int )flags );
1600+ PHP_LIBXML_RESTORE_GLOBALS (xinclude );
15981601
15991602 /* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
16001603 are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
@@ -1634,6 +1637,7 @@ PHP_METHOD(DOMDocument, validate)
16341637
16351638 DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
16361639
1640+ PHP_LIBXML_SANITIZE_GLOBALS (validate );
16371641 cvp = xmlNewValidCtxt ();
16381642
16391643 cvp -> userData = NULL ;
@@ -1645,6 +1649,7 @@ PHP_METHOD(DOMDocument, validate)
16451649 } else {
16461650 RETVAL_FALSE ;
16471651 }
1652+ PHP_LIBXML_RESTORE_GLOBALS (validate );
16481653
16491654 xmlFreeValidCtxt (cvp );
16501655
@@ -1679,14 +1684,18 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
16791684
16801685 DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
16811686
1687+ PHP_LIBXML_SANITIZE_GLOBALS (new_parser_ctxt );
1688+
16821689 switch (type ) {
16831690 case DOM_LOAD_FILE :
16841691 if (CHECK_NULL_PATH (source , source_len )) {
1692+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
16851693 zend_argument_value_error (1 , "must not contain any null bytes" );
16861694 RETURN_THROWS ();
16871695 }
16881696 valid_file = _dom_get_valid_file_path (source , resolved_path , MAXPATHLEN );
16891697 if (!valid_file ) {
1698+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
16901699 php_error_docref (NULL , E_WARNING , "Invalid Schema file source" );
16911700 RETURN_FALSE ;
16921701 }
@@ -1707,6 +1716,7 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
17071716 parser );
17081717 sptr = xmlSchemaParse (parser );
17091718 xmlSchemaFreeParserCtxt (parser );
1719+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
17101720 if (!sptr ) {
17111721 if (!EG (exception )) {
17121722 php_error_docref (NULL , E_WARNING , "Invalid Schema" );
@@ -1727,11 +1737,13 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
17271737 valid_opts |= XML_SCHEMA_VAL_VC_I_CREATE ;
17281738 }
17291739
1740+ PHP_LIBXML_SANITIZE_GLOBALS (validate );
17301741 xmlSchemaSetValidOptions (vptr , valid_opts );
17311742 xmlSchemaSetValidErrors (vptr , php_libxml_error_handler , php_libxml_error_handler , vptr );
17321743 is_valid = xmlSchemaValidateDoc (vptr , docp );
17331744 xmlSchemaFree (sptr );
17341745 xmlSchemaFreeValidCtxt (vptr );
1746+ PHP_LIBXML_RESTORE_GLOBALS (validate );
17351747
17361748 if (is_valid == 0 ) {
17371749 RETURN_TRUE ;
@@ -1802,12 +1814,14 @@ static void _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int typ
18021814 return ;
18031815 }
18041816
1817+ PHP_LIBXML_SANITIZE_GLOBALS (parse );
18051818 xmlRelaxNGSetParserErrors (parser ,
18061819 (xmlRelaxNGValidityErrorFunc ) php_libxml_error_handler ,
18071820 (xmlRelaxNGValidityWarningFunc ) php_libxml_error_handler ,
18081821 parser );
18091822 sptr = xmlRelaxNGParse (parser );
18101823 xmlRelaxNGFreeParserCtxt (parser );
1824+ PHP_LIBXML_RESTORE_GLOBALS (parse );
18111825 if (!sptr ) {
18121826 php_error_docref (NULL , E_WARNING , "Invalid RelaxNG" );
18131827 RETURN_FALSE ;
@@ -1903,6 +1917,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
19031917 ctxt -> sax -> error = php_libxml_ctx_error ;
19041918 ctxt -> sax -> warning = php_libxml_ctx_warning ;
19051919 }
1920+ php_libxml_sanitize_parse_ctxt_options (ctxt );
19061921 if (options ) {
19071922 htmlCtxtUseOptions (ctxt , (int )options );
19081923 }
0 commit comments