Skip to content
Closed
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
5 changes: 3 additions & 2 deletions .github/scripts/windows/test_task.bat
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ set PHP_BUILD_DIR=%PHP_BUILD_OBJ_DIR%\Release
if "%THREAD_SAFE%" equ "1" set PHP_BUILD_DIR=%PHP_BUILD_DIR%_TS

rem prepare for mail
curl -sLo hMailServer.exe https://www.hmailserver.com/download_file/?downloadid=271
hMailServer.exe /verysilent
curl -sLo hMailServer.zip https://downloads.php.net/~windows/php-sdk/deps/vs18/x64/hmailserver-5.7.0-vs18-x64.zip
unzip -q hMailServer.zip -d hMailServer
hMailServer\bin\hMailServer.exe /verysilent
cd %APPVEYOR_BUILD_FOLDER%
%PHP_BUILD_DIR%\php.exe -dextension_dir=%PHP_BUILD_DIR% -dextension=com_dotnet .github\setup_hmailserver.php

Expand Down
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ PHP NEWS
. Fixed segfault in ReflectionMethod::createFromMethodName() on an
uninstantiable subclass. (iliaal)

- Session:
. Fix corruption in mod_mm. (ndossche)
. 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
2 changes: 1 addition & 1 deletion ext/session/mod_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ PS_READ_FUNC(mm)
&& ps_mm_key_exists(data, key) == FAILURE) {
/* key points to PS(id), but cannot change here. */
if (key) {
efree(PS(id));
zend_string_release_ex(PS(id), false);
PS(id) = NULL;
}
PS(id) = PS(mod)->s_create_sid((void **)&data);
Expand Down
3 changes: 3 additions & 0 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ static zend_result php_session_initialize(void) /* {{{ */
if (!PS(id) || !ZSTR_VAL(PS(id))[0]) {
if (PS(id)) {
zend_string_release_ex(PS(id), 0);
PS(id) = NULL;
}
PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
if (!PS(id)) {
Expand All @@ -460,6 +461,7 @@ static zend_result php_session_initialize(void) /* {{{ */
) {
if (PS(id)) {
zend_string_release_ex(PS(id), 0);
PS(id) = NULL;
}
PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
if (!PS(id)) {
Expand Down Expand Up @@ -2440,6 +2442,7 @@ PHP_FUNCTION(session_regenerate_id)
/* Try to generate non-existing ID */
while (limit-- && PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == SUCCESS) {
zend_string_release_ex(PS(id), 0);
PS(id) = NULL;
PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
if (!PS(id)) {
PS(mod)->s_close(&PS(mod_data));
Expand Down
35 changes: 35 additions & 0 deletions ext/session/tests/user_session_module/gh23043.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
GH-23043 (broken session id code can cause zend_mm_heap corrupted)
--EXTENSIONS--
session
--CREDITS--
lmaltsis
--FILE--
<?php
ob_start();
class a extends SessionHandler {
function read($b): string {
return "";
}
function create_sid(): string {
var_dump(session_id());
return '';
}
}
$c = new a;
session_set_save_handler($c);
session_start();
session_write_close();
session_start();
?>
--EXPECTF--
string(0) ""

Warning: SessionHandler::write(): Session ID is too long or contains illegal characters. Only the A-Z, a-z, 0-9, "-", and "," characters are allowed in %s on line %d

Warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: , handler: a::write) in %s on line %d
string(0) ""

Warning: SessionHandler::write(): Session ID is too long or contains illegal characters. Only the A-Z, a-z, 0-9, "-", and "," characters are allowed in Unknown on line 0

Warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: , handler: a::write) in Unknown on line 0
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
2 changes: 1 addition & 1 deletion ext/standard/tests/mail/bug80751.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ foreach (['to' => $to, 'cc' => $cc, 'bcc' => $bcc] as $recipient => $mailAddress
echo "Found the email. {$recipient} received.\n";
}

if ($mail->getHeader('Return-Path') === $from) {
if ($mail->getHeader('Return-Path') === "<{$from}>") {
echo "Return-Path is as expected.\n";
}

Expand Down
Loading