Skip to content

Commit 094e1a8

Browse files
committed
Skip dummy frames allocated on CPU stack of zend_call_function().
(Usage of "current_observed_frame" varible looks unsafe to me).
1 parent a2dcd44 commit 094e1a8

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

Zend/zend_observer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,19 @@ ZEND_API void ZEND_FASTCALL zend_observer_fcall_end(
220220
first_observed_frame = NULL;
221221
current_observed_frame = NULL;
222222
} else {
223-
current_observed_frame = execute_data->prev_execute_data;
223+
zend_execute_data *ex = execute_data->prev_execute_data;
224+
while (ex && !ex->func) {
225+
ex = ex->prev_execute_data;
226+
}
227+
current_observed_frame = ex;
224228
}
225229
}
226230

227231
ZEND_API void zend_observer_fcall_end_all(void)
228232
{
229233
zend_execute_data *ex = current_observed_frame;
230234
while (ex != NULL) {
231-
if (ex->func->type != ZEND_INTERNAL_FUNCTION) {
235+
if (ex->func && ex->func->type != ZEND_INTERNAL_FUNCTION) {
232236
zend_observer_fcall_end(ex, NULL);
233237
}
234238
ex = ex->prev_execute_data;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Observer: End handlers fire after a userland fatal error
3+
--SKIPIF--
4+
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.observe_all=1
8+
zend_test.observer.show_return_value=1
9+
--FILE--
10+
<?php
11+
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
12+
trigger_error('Foo error', E_USER_ERROR);
13+
});
14+
15+
function foo()
16+
{
17+
return $x; // warning
18+
}
19+
20+
foo();
21+
22+
echo 'You should not see this.';
23+
?>
24+
--EXPECTF--
25+
<!-- init '%s%eobserver_error_%d.php' -->
26+
<file '%s%eobserver_error_%d.php'>
27+
<!-- init foo() -->
28+
<foo>
29+
<!-- init {closure}() -->
30+
<{closure}>
31+
32+
Fatal error: Foo error in %s on line %d
33+
</{closure}:NULL>
34+
</foo:NULL>
35+
</file '%s%eobserver_error_%d.php'>

0 commit comments

Comments
 (0)