Skip to content

Commit 9de4eb9

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix #79971: special character is breaking the path in xml function
2 parents 48bc4ea + 0ef1dfc commit 9de4eb9

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
@@ -73,6 +73,11 @@ PHP_METHOD(DOMImplementation, createDocumentType)
7373
pch2 = (xmlChar *) systemid;
7474
}
7575

76+
if (strstr(name, "%00")) {
77+
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
78+
RETURN_FALSE;
79+
}
80+
7681
uri = xmlParseURI(name);
7782
if (uri != NULL && uri->opaque != NULL) {
7883
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
@@ -257,6 +257,10 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
257257
int isescaped=0;
258258
xmlURI *uri;
259259

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

261265
uri = xmlParseURI(filename);
262266
if (uri && (uri->scheme == NULL ||
@@ -436,6 +440,11 @@ php_libxml_output_buffer_create_filename(const char *URI,
436440
if (URI == NULL)
437441
return(NULL);
438442

443+
if (strstr(URI, "%00")) {
444+
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
445+
return NULL;
446+
}
447+
439448
puri = xmlParseURI(URI);
440449
if (puri != NULL) {
441450
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)