Skip to content

Commit ca87d46

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79971: special character is breaking the path in xml function
2 parents b2cf9b7 + f15f8fc commit ca87d46

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

ext/dom/domimplementation.c

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ PHP_METHOD(domimplementation, createDocumentType)
112112
pch2 = (xmlChar *) systemid;
113113
}
114114

115+
if (strstr(name, "%00")) {
116+
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
117+
RETURN_FALSE;
118+
}
119+
115120
uri = xmlParseURI(name);
116121
if (uri != NULL && uri->opaque != NULL) {
117122
localname = xmlStrdup((xmlChar *) uri->opaque);

ext/dom/tests/bug79971_2.phpt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #79971 (special character is breaking the path in xml function)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('dom')) die('skip dom extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$imp = new DOMImplementation;
10+
if (PHP_OS_FAMILY === 'Windows') {
11+
$path = '/' . str_replace('\\', '/', __DIR__);
12+
} else {
13+
$path = __DIR__;
14+
}
15+
$uri = "file://$path/bug79971_2.xml";
16+
var_dump($imp->createDocumentType("$uri%00foo"));
17+
?>
18+
--EXPECTF--
19+
Warning: DOMImplementation::createDocumentType(): URI must not contain percent-encoded NUL bytes in %s on line %d
20+
bool(false)

ext/libxml/libxml.c

+9
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
303303
int isescaped=0;
304304
xmlURI *uri;
305305

306+
if (strstr(filename, "%00")) {
307+
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
308+
return NULL;
309+
}
306310

307311
uri = xmlParseURI(filename);
308312
if (uri && (uri->scheme == NULL ||
@@ -482,6 +486,11 @@ php_libxml_output_buffer_create_filename(const char *URI,
482486
if (URI == NULL)
483487
return(NULL);
484488

489+
if (strstr(URI, "%00")) {
490+
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
491+
return NULL;
492+
}
493+
485494
puri = xmlParseURI(URI);
486495
if (puri != NULL) {
487496
if (puri->scheme != NULL)

ext/simplexml/tests/bug79971_1.phpt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #79971 (special character is breaking the path in xml function)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('simplexml')) die('skip simplexml extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
if (PHP_OS_FAMILY === 'Windows') {
10+
$path = '/' . str_replace('\\', '/', __DIR__);
11+
} else {
12+
$path = __DIR__;
13+
}
14+
$uri = "file://$path/bug79971_1.xml";
15+
var_dump(simplexml_load_file("$uri%00foo"));
16+
17+
$sxe = simplexml_load_file($uri);
18+
var_dump($sxe->asXML("$uri.out%00foo"));
19+
?>
20+
--EXPECTF--
21+
Warning: simplexml_load_file(): URI must not contain percent-encoded NUL bytes in %s on line %d
22+
23+
Warning: simplexml_load_file(): I/O warning : failed to load external entity "%s/bug79971_1.xml%00foo" in %s on line %d
24+
bool(false)
25+
26+
Warning: SimpleXMLElement::asXML(): URI must not contain percent-encoded NUL bytes in %s on line %d
27+
bool(false)

ext/simplexml/tests/bug79971_1.xml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0"?>
2+
<root></root>

0 commit comments

Comments
 (0)