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 @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.2.36

- Standard:
. Fixed use-after-free in parse_str() when an error handler replaces the
result variable. (cataphract)



21 Oct 2026, PHP 8.2.35
Expand Down
8 changes: 5 additions & 3 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -4875,6 +4875,7 @@ PHP_FUNCTION(parse_str)
{
char *arg;
zval *arrayArg = NULL;
zval array;
char *res = NULL;
size_t arglen;

Expand All @@ -4883,13 +4884,14 @@ PHP_FUNCTION(parse_str)
Z_PARAM_ZVAL(arrayArg)
ZEND_PARSE_PARAMETERS_END();

arrayArg = zend_try_array_init(arrayArg);
if (!arrayArg) {
if (!zend_try_array_init(arrayArg)) {
RETURN_THROWS();
}

array_init(&array);
res = estrndup(arg, arglen);
sapi_module.treat_data(PARSE_STRING, res, arrayArg);
sapi_module.treat_data(PARSE_STRING, res, &array);
ZEND_TRY_ASSIGN_REF_VALUE(arrayArg, &array);
}
/* }}} */

Expand Down
30 changes: 30 additions & 0 deletions ext/standard/tests/strings/parse_str_error_handler_uaf.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
parse_str() remains safe when its error handler replaces the result array
--INI--
display_errors=0
max_input_nesting_level=1
--FILE--
<?php
$result = null;
$handled = 0;

set_error_handler(function (int $errno, string $message) use (&$result, &$handled): bool {
if ($errno === E_WARNING
&& strpos($message, 'Input variable nesting level exceeded') !== false) {
$handled++;
$result = null;
return true;
}

return false;
});

parse_str('a[b][c]=1&later=2', $result);
restore_error_handler();

var_dump($handled);
echo "done\n";
?>
--EXPECT--
int(1)
done
Loading