Skip to content

Commit 3941294

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

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

Zend/tests/bug62763.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ class test1 {
77
register_shutdown_function(array($this, 'shutdown'));
88
}
99
public function shutdown() {
10-
exit(__METHOD__);
10+
exit(static::class . '::' . __FUNCTION__ . "\n");
1111
}
1212
}
1313

1414
class test2 extends test1 {
1515
public function __destruct() {
16-
exit (__METHOD__);
16+
exit(static::class . '::' . __FUNCTION__ . "\n");
1717
}
1818
}
1919
new test1;
2020
new test2;
2121
?>
2222
--EXPECT--
23-
test1::shutdowntest2::__destruct
23+
test1::shutdown
24+
test2::shutdown
25+
test2::__destruct

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)