From 8c6a7c3326f000af0a8ea266143059e5a463e626 Mon Sep 17 00:00:00 2001 From: Mark Plomer Date: Mon, 24 Feb 2020 21:32:02 +0100 Subject: [PATCH] Fix #63206: Fully support error/exception_handler stacking, even with null or inside the handler Always push the current user_error/exception_handler to the stack, even when it is empty, so restore_error_handler() always works as expected. The user_error_handler is especially temporarily empty when we are inside the error handler, which caused inconsistent behaviour before. --- NEWS | 4 ++++ Zend/tests/bug63206.phpt | 29 +++++++++++++++++++++++++++++ Zend/tests/bug63206_1.phpt | 26 ++++++++++++++++++++++++++ Zend/tests/bug63206_2.phpt | 26 ++++++++++++++++++++++++++ Zend/zend_builtin_functions.c | 10 +++++----- 5 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 Zend/tests/bug63206.phpt create mode 100644 Zend/tests/bug63206_1.phpt create mode 100644 Zend/tests/bug63206_2.phpt diff --git a/NEWS b/NEWS index 64682a8d07..12208cf46a 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 7.3.16 +- Core: + . Fixed bug #63206 (restore_error_handler does not restore previous errors + mask). (Mark Plomer) + - COM: . Fixed bug #66322 (COMPersistHelper::SaveToFile can save to wrong location). (cmb) diff --git a/Zend/tests/bug63206.phpt b/Zend/tests/bug63206.phpt new file mode 100644 index 0000000000..dc7bb1fd1d --- /dev/null +++ b/Zend/tests/bug63206.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #63206 Fully support error_handler stacking, even inside the error_handler +--FILE-- + +--EXPECTF-- +Second handler +Internal handler +Second handler +Internal handler diff --git a/Zend/tests/bug63206_1.phpt b/Zend/tests/bug63206_1.phpt new file mode 100644 index 0000000000..f08f913824 --- /dev/null +++ b/Zend/tests/bug63206_1.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #63206 Fully support error_handler stacking, even with null +--FILE-- + +--EXPECTF-- +Second handler diff --git a/Zend/tests/bug63206_2.phpt b/Zend/tests/bug63206_2.phpt new file mode 100644 index 0000000000..7a2bf38543 --- /dev/null +++ b/Zend/tests/bug63206_2.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #63206 Fully support exception_handler stacking, even with null +--FILE-- + +--EXPECTF-- +Second handler diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index f4c4a4f31d..69fbeec1e1 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1665,11 +1665,11 @@ ZEND_FUNCTION(set_error_handler) if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) { ZVAL_COPY(return_value, &EG(user_error_handler)); - - zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting)); - zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler)); } + zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting)); + zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler)); + if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */ ZVAL_UNDEF(&EG(user_error_handler)); return; @@ -1732,10 +1732,10 @@ ZEND_FUNCTION(set_exception_handler) if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { ZVAL_COPY(return_value, &EG(user_exception_handler)); - - zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler)); } + zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler)); + if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */ ZVAL_UNDEF(&EG(user_exception_handler)); return; -- 2.40.0