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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ PHP NEWS
comparison. (Arnaud)
. Fixed OSS-Fuzz #536440507 (Immutable class incorrect assertion).
(ndossche)
. Fixed bug GH-23896 (Assertion failure in zend_call_function() when the
error handler throws while resolving a self::/parent::/static::
callable). (Lazizbek Ergashev)

- DOM:
. Fixed use-after-free when re-constructing a DOMXPath whose php:function
Expand Down
33 changes: 33 additions & 0 deletions Zend/tests/gh23896.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
GH-23896 (Assertion failure in zend_call_function() when the error handler throws during parent:: callable resolution)
--FILE--
<?php
set_error_handler(function ($severity, $m) {
throw new Exception($m, $severity);
});
spl_autoload_register(function ($class) {
if ($class === 'Loader') {
throw new Exception("Cannot load $class");
}
});
class P {}
class C extends P {
public function u(string $s) {
return unserialize($s);
}
}
foreach (['parent::my_unserialize', 'Loader::load'] as $callback) {
ini_set('unserialize_callback_func', $callback);
try {
(new C)->u('O:3:"FOO":0:{}');
} catch (Exception $e) {
echo $e->getMessage(), "\n";
var_dump($e->getPrevious());
}
}
?>
--EXPECT--
Use of "parent" in callables is deprecated
NULL
Cannot load Loader
NULL
6 changes: 6 additions & 0 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,12 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_
}

if (!zend_is_callable_ex(&fci->function_name, fci->object, 0, NULL, fci_cache, &error)) {
if (EG(exception)) {
if (error) {
efree(error);
}
return SUCCESS;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather flip the condition, that "if EG(exception) return" and keep the existing assertion below the new if.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9691d2c. The error string can still be set here when a throwing autoloader causes the failure, so I free it before the return. In that case the autoloader exception now propagates alone, with no "Invalid callback" Error chained on top. This is the same as the ZPP path. I added that case to the test.

ZEND_ASSERT(error && "Should have error if not callable");
zend_string *callable_name
= zend_get_callable_name_ex(&fci->function_name, fci->object);
Expand Down
4 changes: 1 addition & 3 deletions ext/xsl/tests/throw_in_autoload.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ $proc->registerPhpFunctions();
$xsl = $proc->importStylesheet($xsl);
try {
$newdom = $proc->transformToDoc($inputdom);
} catch (Error $e) {
} catch (Exception $e) {
echo $e->getMessage(), "\n";
echo $e->getPrevious()->getMessage(), "\n";
}
?>
===DONE===
--EXPECT--
string(4) "TeSt"
Invalid callback TeSt::dateLang, class "TeSt" not found
Autoload exception
===DONE===
Loading