@@ -1281,6 +1281,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
1281
1281
options |= XML_PARSE_NOBLANKS ;
1282
1282
}
1283
1283
1284
+ php_libxml_sanitize_parse_ctxt_options (ctxt );
1284
1285
xmlCtxtUseOptions (ctxt , options );
1285
1286
1286
1287
ctxt -> recovery = recover ;
@@ -1575,7 +1576,9 @@ PHP_METHOD(DOMDocument, xinclude)
1575
1576
1576
1577
DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
1577
1578
1579
+ PHP_LIBXML_SANITIZE_GLOBALS (xinclude );
1578
1580
err = xmlXIncludeProcessFlags (docp , (int )flags );
1581
+ PHP_LIBXML_RESTORE_GLOBALS (xinclude );
1579
1582
1580
1583
/* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
1581
1584
are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
@@ -1613,6 +1616,7 @@ PHP_METHOD(DOMDocument, validate)
1613
1616
1614
1617
DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
1615
1618
1619
+ PHP_LIBXML_SANITIZE_GLOBALS (validate );
1616
1620
cvp = xmlNewValidCtxt ();
1617
1621
1618
1622
cvp -> userData = NULL ;
@@ -1624,6 +1628,7 @@ PHP_METHOD(DOMDocument, validate)
1624
1628
} else {
1625
1629
RETVAL_FALSE ;
1626
1630
}
1631
+ PHP_LIBXML_RESTORE_GLOBALS (validate );
1627
1632
1628
1633
xmlFreeValidCtxt (cvp );
1629
1634
@@ -1658,14 +1663,18 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
1658
1663
1659
1664
DOM_GET_OBJ (docp , id , xmlDocPtr , intern );
1660
1665
1666
+ PHP_LIBXML_SANITIZE_GLOBALS (new_parser_ctxt );
1667
+
1661
1668
switch (type ) {
1662
1669
case DOM_LOAD_FILE :
1663
1670
if (CHECK_NULL_PATH (source , source_len )) {
1671
+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
1664
1672
zend_argument_value_error (1 , "must not contain any null bytes" );
1665
1673
RETURN_THROWS ();
1666
1674
}
1667
1675
valid_file = _dom_get_valid_file_path (source , resolved_path , MAXPATHLEN );
1668
1676
if (!valid_file ) {
1677
+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
1669
1678
php_error_docref (NULL , E_WARNING , "Invalid Schema file source" );
1670
1679
RETURN_FALSE ;
1671
1680
}
@@ -1686,6 +1695,7 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
1686
1695
parser );
1687
1696
sptr = xmlSchemaParse (parser );
1688
1697
xmlSchemaFreeParserCtxt (parser );
1698
+ PHP_LIBXML_RESTORE_GLOBALS (new_parser_ctxt );
1689
1699
if (!sptr ) {
1690
1700
if (!EG (exception )) {
1691
1701
php_error_docref (NULL , E_WARNING , "Invalid Schema" );
@@ -1706,11 +1716,13 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
1706
1716
valid_opts |= XML_SCHEMA_VAL_VC_I_CREATE ;
1707
1717
}
1708
1718
1719
+ PHP_LIBXML_SANITIZE_GLOBALS (validate );
1709
1720
xmlSchemaSetValidOptions (vptr , valid_opts );
1710
1721
xmlSchemaSetValidErrors (vptr , php_libxml_error_handler , php_libxml_error_handler , vptr );
1711
1722
is_valid = xmlSchemaValidateDoc (vptr , docp );
1712
1723
xmlSchemaFree (sptr );
1713
1724
xmlSchemaFreeValidCtxt (vptr );
1725
+ PHP_LIBXML_RESTORE_GLOBALS (validate );
1714
1726
1715
1727
if (is_valid == 0 ) {
1716
1728
RETURN_TRUE ;
@@ -1781,12 +1793,14 @@ static void _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int typ
1781
1793
return ;
1782
1794
}
1783
1795
1796
+ PHP_LIBXML_SANITIZE_GLOBALS (parse );
1784
1797
xmlRelaxNGSetParserErrors (parser ,
1785
1798
(xmlRelaxNGValidityErrorFunc ) php_libxml_error_handler ,
1786
1799
(xmlRelaxNGValidityWarningFunc ) php_libxml_error_handler ,
1787
1800
parser );
1788
1801
sptr = xmlRelaxNGParse (parser );
1789
1802
xmlRelaxNGFreeParserCtxt (parser );
1803
+ PHP_LIBXML_RESTORE_GLOBALS (parse );
1790
1804
if (!sptr ) {
1791
1805
php_error_docref (NULL , E_WARNING , "Invalid RelaxNG" );
1792
1806
RETURN_FALSE ;
@@ -1885,6 +1899,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
1885
1899
ctxt -> sax -> error = php_libxml_ctx_error ;
1886
1900
ctxt -> sax -> warning = php_libxml_ctx_warning ;
1887
1901
}
1902
+ php_libxml_sanitize_parse_ctxt_options (ctxt );
1888
1903
if (options ) {
1889
1904
htmlCtxtUseOptions (ctxt , (int )options );
1890
1905
}
0 commit comments