From 1db734db6663ffd2f0e5294976e41e2d0f0855f0 Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Tue, 6 May 2025 21:48:59 +0300 Subject: [PATCH] fix: disallow using multiple throw expressions --- Zend/tests/throw/throw_throw_throw.phpt | 12 ++++++++++++ Zend/zend_compile.c | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 Zend/tests/throw/throw_throw_throw.phpt diff --git a/Zend/tests/throw/throw_throw_throw.phpt b/Zend/tests/throw/throw_throw_throw.phpt new file mode 100644 index 0000000000000..c4d765acc9f7f --- /dev/null +++ b/Zend/tests/throw/throw_throw_throw.phpt @@ -0,0 +1,12 @@ +--TEST-- +throw throw guard +--FILE-- + +--EXPECTF-- +Fatal error: Cannot throw throw expression in %s on line %d \ No newline at end of file diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index cb64729806a23..2bdcb87b2d012 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5746,6 +5746,10 @@ static void zend_compile_throw(znode *result, zend_ast *ast) /* {{{ */ { zend_ast *expr_ast = ast->child[0]; + if (expr_ast->kind == ZEND_AST_THROW) { + zend_error_noreturn(E_COMPILE_ERROR, "Cannot throw throw expression"); + } + znode expr_node; zend_compile_expr(&expr_node, expr_ast);