From dae12d80cfa46728ac3e528aab99a91d7170977e Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 6 Jul 2023 22:45:29 +0200 Subject: [PATCH] Fix accidental handling of unwind and gracful exit exceptions These exceptions should not invoke the user error handler. Fixes GH-11601 --- Zend/zend_exceptions.c | 8 +++++++- Zend/zend_execute_API.c | 6 +----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index ed062958f5086..7dcf2ad65b7f6 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -199,8 +199,14 @@ ZEND_API ZEND_COLD void zend_throw_exception_internal(zend_object *exception) /* return; } if (EG(exception)) { - if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { + if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF + && !zend_is_unwind_exit(EG(exception)) + && !zend_is_graceful_exit(EG(exception))) { zend_user_exception_handler(); + if (EG(exception)) { + zend_exception_error(EG(exception), E_ERROR); + } + return; } else { zend_exception_error(EG(exception), E_ERROR); } diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index dfb13005f6470..c1a5e31f7e6d9 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -1010,11 +1010,7 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_ if (UNEXPECTED(EG(exception))) { if (UNEXPECTED(!EG(current_execute_data))) { - if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { - zend_user_exception_handler(); - } else { - zend_throw_exception_internal(NULL); - } + zend_throw_exception_internal(NULL); } else if (EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { zend_rethrow_exception(EG(current_execute_data));