From 094e1a8b2def767b41d2defaf7cb86681126f9da Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 26 Jan 2021 18:41:26 +0300 Subject: [PATCH] Skip dummy frames allocated on CPU stack of zend_call_function(). (Usage of "current_observed_frame" varible looks unsafe to me). --- Zend/zend_observer.c | 8 +++-- ext/zend_test/tests/observer_error_05.phpt | 35 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 ext/zend_test/tests/observer_error_05.phpt diff --git a/Zend/zend_observer.c b/Zend/zend_observer.c index a8ce1eb5c0..a60428ee04 100644 --- a/Zend/zend_observer.c +++ b/Zend/zend_observer.c @@ -220,7 +220,11 @@ ZEND_API void ZEND_FASTCALL zend_observer_fcall_end( first_observed_frame = NULL; current_observed_frame = NULL; } else { - current_observed_frame = execute_data->prev_execute_data; + zend_execute_data *ex = execute_data->prev_execute_data; + while (ex && !ex->func) { + ex = ex->prev_execute_data; + } + current_observed_frame = ex; } } @@ -228,7 +232,7 @@ ZEND_API void zend_observer_fcall_end_all(void) { zend_execute_data *ex = current_observed_frame; while (ex != NULL) { - if (ex->func->type != ZEND_INTERNAL_FUNCTION) { + if (ex->func && ex->func->type != ZEND_INTERNAL_FUNCTION) { zend_observer_fcall_end(ex, NULL); } ex = ex->prev_execute_data; diff --git a/ext/zend_test/tests/observer_error_05.phpt b/ext/zend_test/tests/observer_error_05.phpt new file mode 100644 index 0000000000..d3e5f67a4e --- /dev/null +++ b/ext/zend_test/tests/observer_error_05.phpt @@ -0,0 +1,35 @@ +--TEST-- +Observer: End handlers fire after a userland fatal error +--SKIPIF-- + +--INI-- +zend_test.observer.enabled=1 +zend_test.observer.observe_all=1 +zend_test.observer.show_return_value=1 +--FILE-- + +--EXPECTF-- + + + + + + <{closure}> + +Fatal error: Foo error in %s on line %d + + + -- 2.40.0