Rethrow exceptions in fiber destructor

We need to make sure that HANDLE_EXCEPTION is set when the fiber
throws during destruction.

Fixes oss-fuzz #33875.
This commit is contained in:
Nikita Popov 2021-05-05 12:49:47 +02:00
parent c15dc63ad2
commit fb374f56a7
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,21 @@
--TEST--
Make sure exceptions are rethrown when throwing from fiber destructor
--FILE--
<?php
$fiber = new Fiber(function() {
try {
Fiber::suspend();
} finally {
throw new Exception("Exception 2");
}
});
$fiber->start();
unset($fiber);
throw new Exception("Exception 1");
?>
--EXPECTF--
Fatal error: Uncaught Exception: Exception 2 in %s:%d
Stack trace:
#0 [internal function]: {closure}()
#1 {main}
thrown in %s on line %d

View File

@ -398,6 +398,11 @@ static void zend_fiber_object_destroy(zend_object *object)
zend_fiber_switch_to(fiber);
if (EG(exception)) {
if (!exception && EG(current_execute_data) && EG(current_execute_data)->func
&& ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) {
zend_rethrow_exception(EG(current_execute_data));
}
zend_exception_set_previous(EG(exception), exception);
if (EG(flags) & EG_FLAGS_IN_SHUTDOWN) {