Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ PHP NEWS
. Fixed bug GH-23043 (broken session id code can cause zend_mm_heap
corrupted). (ndossche)

- SimpleXML:
. Fixed SimpleXMLElement::__construct() accepting embedded null bytes in
URL/path mode. (iliaal)

- Sockets:
. Fixed various memory related issues in ext/sockets. (David Carlier)

Expand Down
5 changes: 5 additions & 0 deletions ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,11 @@ PHP_METHOD(SimpleXMLElement, __construct)
RETURN_THROWS();
}

if (is_url && CHECK_NULL_PATH(data, data_len)) {
zend_argument_value_error(1, "must not contain any null bytes");
RETURN_THROWS();
}

PHP_LIBXML_SANITIZE_GLOBALS(read_file_or_memory);
docp = is_url ? xmlReadFile(data, NULL, (int)options) : xmlReadMemory(data, (int)data_len, NULL, NULL, (int)options);
PHP_LIBXML_RESTORE_GLOBALS(read_file_or_memory);
Expand Down
26 changes: 26 additions & 0 deletions ext/simplexml/tests/bug_sxe_ctor_nul_path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
SimpleXMLElement constructor rejects embedded NUL in URL/path mode
--EXTENSIONS--
simplexml
--FILE--
<?php
$tmp = tempnam(sys_get_temp_dir(), 'sxe');
file_put_contents($tmp, '<r/>');
$path = $tmp . "\0evil";
try {
new SimpleXMLElement($path, 0, true);
echo "ctor: loaded\n";
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}
try {
simplexml_load_file($path);
echo "load_file: loaded\n";
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}
unlink($tmp);
?>
--EXPECT--
ValueError: SimpleXMLElement::__construct(): Argument #1 ($data) must not contain any null bytes
ValueError: simplexml_load_file(): Argument #1 ($filename) must not contain any null bytes
Loading