Skip to content

Commit f7ceb53

Browse files
committed
Skip bailout for unwind and graceful exit in zend_throw_exception_internal()
Fixes GH-18619
1 parent aadd724 commit f7ceb53

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Zend/tests/gh18619.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Gh-18619: exit() from error handler should not trigger bailout
3+
--FILE--
4+
<?php
5+
6+
function foo($e) {
7+
exit;
8+
}
9+
10+
set_exception_handler('foo');
11+
12+
register_shutdown_function(function () {
13+
var_dump(set_exception_handler(null));
14+
});
15+
16+
throw new Error();
17+
18+
?>
19+
--EXPECT--
20+
string(3) "foo"

Zend/zend_exceptions.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,13 @@ ZEND_API ZEND_COLD void zend_throw_exception_internal(zend_object *exception) /*
210210
return;
211211
}
212212
if (EG(exception)) {
213-
if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF
214-
&& !zend_is_unwind_exit(EG(exception))
215-
&& !zend_is_graceful_exit(EG(exception))) {
213+
if (zend_is_unwind_exit(EG(exception))
214+
|| zend_is_graceful_exit(EG(exception))) {
215+
/* Stack is fully unwound, clear the unwind exit. */
216+
zend_exception_error(EG(exception), E_ERROR);
217+
return;
218+
}
219+
if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
216220
zend_user_exception_handler();
217221
if (EG(exception)) {
218222
zend_exception_error(EG(exception), E_ERROR);

0 commit comments

Comments
 (0)