From f14e5cfaaa0c56fe38d8f8cce72cfdcaa5bd7dba Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 3 Oct 2024 00:44:16 +0200 Subject: [PATCH] Fix GH-16181: phpdbg: exit in exception handler reports fatal error When running PHP code, we must not handle `UnwindExit` exceptions, but rather have to ignore them. Closes GH-16182. --- NEWS | 2 ++ sapi/phpdbg/phpdbg_prompt.c | 2 +- sapi/phpdbg/tests/gh16181.phpt | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 sapi/phpdbg/tests/gh16181.phpt diff --git a/NEWS b/NEWS index c7457b839e8..f2c17a45365 100644 --- a/NEWS +++ b/NEWS @@ -39,6 +39,8 @@ PHP NEWS - PHPDBG: . Fixed bug GH-15901 (phpdbg: Assertion failure on i funcs). (cmb) + . Fixed bug GH-16181 (phpdbg: exit in exception handler reports fatal error). + (cmb) - SimpleXML: . Fixed bug GH-15837 (Segmentation fault in ext/simplexml/simplexml.c). diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 887064cf2e7..448194f13d2 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -907,7 +907,7 @@ free_cmd: } } zend_end_try(); - if (EG(exception)) { + if (EG(exception) && !zend_is_unwind_exit(EG(exception))) { phpdbg_handle_exception(); } } diff --git a/sapi/phpdbg/tests/gh16181.phpt b/sapi/phpdbg/tests/gh16181.phpt new file mode 100644 index 00000000000..478bbb98ca0 --- /dev/null +++ b/sapi/phpdbg/tests/gh16181.phpt @@ -0,0 +1,26 @@ +--TEST-- +GH-16181 (phpdbg: exit in exception handler reports fatal error) +--PHPDBG-- +r +c +q +--FILE-- + +--EXPECTF-- +[Successful compilation of %s] +prompt> throwing exception +[Uncaught Exception in %s on line %d: oh noes] +>00008: throw new \Exception("oh noes"); + 00009: ?> + 00010: +prompt> exception caught +[Script ended normally] +prompt>