From 523273354a053b3390dfd74a7215582b6e32c1d4 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Tue, 24 Jan 2023 19:11:04 -0600 Subject: [PATCH] Fix GH-10437: Set active fiber to null on bailout --- NEWS | 2 ++ Zend/tests/fibers/gh10437.phpt | 18 ++++++++++++++++++ Zend/zend_fibers.c | 1 + 3 files changed, 21 insertions(+) create mode 100644 Zend/tests/fibers/gh10437.phpt diff --git a/NEWS b/NEWS index 411201c1acca1..3583a625cf8cb 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ PHP NEWS . Fixed overflow check in OnUpdateMemoryConsumption. (nielsdos) . Fixed bug GH-9916 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes). (Arnaud) + . Fixed bug GH-10437 (Segfault/assertion when using fibers in shutdown + function after bailout). (trowski) - FFI: . Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos) diff --git a/Zend/tests/fibers/gh10437.phpt b/Zend/tests/fibers/gh10437.phpt new file mode 100644 index 0000000000000..5c793c986ee29 --- /dev/null +++ b/Zend/tests/fibers/gh10437.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-10437 (Segfault/assertion when using fibers in shutdown function after bailout) +--FILE-- +start(); + +?> +--EXPECTF-- +Fatal error: Bailout in fiber in %sgh10437.php on line %d +NULL diff --git a/Zend/zend_fibers.c b/Zend/zend_fibers.c index caa35c61983be..051a9dceaea7a 100644 --- a/Zend/zend_fibers.c +++ b/Zend/zend_fibers.c @@ -543,6 +543,7 @@ static zend_always_inline zend_fiber_transfer zend_fiber_switch_to( /* Forward bailout into current fiber. */ if (UNEXPECTED(transfer.flags & ZEND_FIBER_TRANSFER_FLAG_BAILOUT)) { + EG(active_fiber) = NULL; zend_bailout(); }