Skip to content

Commit 24e669e

Browse files
committed
backport zend_test changes (zend_test_override_libxml_global_state)
1 parent ef1d507 commit 24e669e

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

ext/dom/tests/libxml_global_state_entity_loader_bypass.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GHSA-3qrf-m4j2-pcrr (libxml global state entity loader bypass)
55
if (!extension_loaded('libxml')) die('skip libxml extension not available');
66
if (!extension_loaded('dom')) die('skip dom extension not available');
77
if (!extension_loaded('zend-test')) die('skip zend-test extension not available');
8+
if (!function_exists('zend_test_override_libxml_global_state')) die('skip not for Windows');
89
?>
910
--FILE--
1011
<?php

ext/simplexml/tests/libxml_global_state_entity_loader_bypass.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GHSA-3qrf-m4j2-pcrr (libxml global state entity loader bypass)
55
if (!extension_loaded('libxml')) die('skip libxml extension not available');
66
if (!extension_loaded('simplexml')) die('skip simplexml extension not available');
77
if (!extension_loaded('zend-test')) die('skip zend-test extension not available');
8+
if (!function_exists('zend_test_override_libxml_global_state')) die('skip not for Windows');
89
?>
910
--FILE--
1011
<?php

ext/xmlreader/tests/libxml_global_state_entity_loader_bypass.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GHSA-3qrf-m4j2-pcrr (libxml global state entity loader bypass)
55
if (!extension_loaded('libxml')) die('skip libxml extension not available');
66
if (!extension_loaded('xmlreader')) die('skip xmlreader extension not available');
77
if (!extension_loaded('zend-test')) die('skip zend-test extension not available');
8+
if (!function_exists('zend_test_override_libxml_global_state')) die('skip not for Windows');
89
?>
910
--FILE--
1011
<?php
@@ -15,11 +16,11 @@ libxml_use_internal_errors(true);
1516
zend_test_override_libxml_global_state();
1617

1718
echo "--- String test ---\n";
18-
$reader = XMLReader::xml($xml);
19+
$reader = @XMLReader::xml($xml);
1920
$reader->read();
2021
echo "--- File test ---\n";
2122
file_put_contents("libxml_global_state_entity_loader_bypass.tmp", $xml);
22-
$reader = XMLReader::open("libxml_global_state_entity_loader_bypass.tmp");
23+
$reader = @XMLReader::open("libxml_global_state_entity_loader_bypass.tmp");
2324
$reader->read();
2425

2526
echo "Done\n";

ext/zend_test/test.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include "ext/standard/info.h"
2626
#include "php_test.h"
2727

28+
#if defined(HAVE_LIBXML) && !defined(PHP_WIN32)
29+
# include <libxml/globals.h>
30+
# include <libxml/parser.h>
31+
#endif
32+
2833
static zend_class_entry *zend_test_interface;
2934
static zend_class_entry *zend_test_class;
3035
static zend_class_entry *zend_test_child_class;
@@ -48,6 +53,20 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_zend_leak_variable, 0, 0, 1)
4853
ZEND_ARG_INFO(0, variable)
4954
ZEND_END_ARG_INFO()
5055

56+
#if defined(HAVE_LIBXML) && !defined(PHP_WIN32)
57+
static ZEND_FUNCTION(zend_test_override_libxml_global_state)
58+
{
59+
ZEND_PARSE_PARAMETERS_NONE();
60+
61+
xmlLoadExtDtdDefaultValue = 1;
62+
xmlDoValidityCheckingDefaultValue = 1;
63+
(void) xmlPedanticParserDefault(1);
64+
(void) xmlSubstituteEntitiesDefault(1);
65+
(void) xmlLineNumbersDefault(1);
66+
(void) xmlKeepBlanksDefault(0);
67+
}
68+
#endif
69+
5170
ZEND_FUNCTION(zend_test_func)
5271
{
5372
/* dummy */
@@ -297,6 +316,9 @@ static const zend_function_entry zend_test_functions[] = {
297316
ZEND_FE(zend_terminate_string, arginfo_zend_terminate_string)
298317
ZEND_FE(zend_leak_bytes, NULL)
299318
ZEND_FE(zend_leak_variable, arginfo_zend_leak_variable)
319+
#if defined(HAVE_LIBXML) && !defined(PHP_WIN32)
320+
ZEND_FE(zend_test_override_libxml_global_state, NULL)
321+
#endif
300322
ZEND_FE_END
301323
};
302324

0 commit comments

Comments
 (0)