From 284c29328ee2116c3025482188d2bd880a7f3f37 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 28 Jan 2023 10:13:58 -0600 Subject: [PATCH 1/2] Fix GH-10437: Set active fiber to null on bailout (#10443) --- 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 411201c1acc..3583a625cf8 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 00000000000..5c793c986ee --- /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 caa35c61983..051a9dceaea 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(); } From 5e1b9666a9a571077986c9be603858961c55c669 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 28 Jan 2023 10:18:12 -0600 Subject: [PATCH 2/2] [ci skip] NEWS --- NEWS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 5594fb3855d..6fbe29aae41 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,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) @@ -554,4 +556,3 @@ PHP NEWS . On Windows, the Zip extension is now built as shared library (DLL) by default. (cmb) . Implement fseek for zip stream when possible with libzip 1.9.1. (Remi) -