Skip to content

Commit 0ef1dfc

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

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

ext/dom/domimplementation.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ PHP_METHOD(DOMImplementation, createDocumentType)
7878
pch2 = (xmlChar *) systemid;
7979
}
8080

81+
if (strstr(name, "%00")) {
82+
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
83+
RETURN_FALSE;
84+
}
85+
8186
uri = xmlParseURI(name);
8287
if (uri != NULL && uri->opaque != NULL) {
8388
localname = xmlStrdup((xmlChar *) uri->opaque);

ext/dom/tests/bug79971_2.phpt

Lines changed: 20 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
255255
int isescaped=0;
256256
xmlURI *uri;
257257

258+
if (strstr(filename, "%00")) {
259+
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
260+
return NULL;
261+
}
258262

259263
uri = xmlParseURI(filename);
260264
if (uri && (uri->scheme == NULL ||
@@ -434,6 +438,11 @@ php_libxml_output_buffer_create_filename(const char *URI,
434438
if (URI == NULL)
435439
return(NULL);
436440

441+
if (strstr(URI, "%00")) {
442+
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
443+
return NULL;
444+
}
445+
437446
puri = xmlParseURI(URI);
438447
if (puri != NULL) {
439448
if (puri->scheme != NULL)

ext/simplexml/tests/bug79971_1.phpt

Lines changed: 27 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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)