Skip to content

Commit 19759a5

Browse files
nikita2206laruence
authored andcommitted
Fix RECV opcode to handle all kinds of exceptions
fix RECV opcode to handle exceptions thrown from user-defined error handler as a result Notice error from failed type coercion
1 parent 7d93363 commit 19759a5

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Zend/tests/bug72057.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #72057 (PHP hangs when user error handler throws exception after Notice from type coercion)
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(
7+
function() {
8+
throw new Exception("My custom error");
9+
}
10+
);
11+
12+
(function (int $i) { bar(); })("7as");
13+
14+
--EXPECTF--
15+
16+
Fatal error: Uncaught Exception: My custom error in %s:%d
17+
Stack trace:
18+
#0 %s(%d): {closure}(8, 'A non well form...', '%s', %d, Array)
19+
#1 %s(%d): {closure}('7as')
20+
#2 {main}
21+
thrown in %s on line %d

Zend/zend_vm_def.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4704,7 +4704,7 @@ ZEND_VM_HANDLER(63, ZEND_RECV, ANY, ANY)
47044704
zval *param = _get_zval_ptr_cv_undef_BP_VAR_W(execute_data, opline->result.var);
47054705

47064706
SAVE_OPLINE();
4707-
if (UNEXPECTED(!zend_verify_arg_type(EX(func), arg_num, param, NULL, CACHE_ADDR(opline->op2.num)))) {
4707+
if (UNEXPECTED(!zend_verify_arg_type(EX(func), arg_num, param, NULL, CACHE_ADDR(opline->op2.num)) || EG(exception))) {
47084708
HANDLE_EXCEPTION();
47094709
}
47104710
}
@@ -4742,7 +4742,7 @@ ZEND_VM_HANDLER(64, ZEND_RECV_INIT, ANY, CONST)
47424742
zval *default_value = EX_CONSTANT(opline->op2);
47434743

47444744
SAVE_OPLINE();
4745-
if (UNEXPECTED(!zend_verify_arg_type(EX(func), arg_num, param, default_value, CACHE_ADDR(Z_CACHE_SLOT_P(default_value))))) {
4745+
if (UNEXPECTED(!zend_verify_arg_type(EX(func), arg_num, param, default_value, CACHE_ADDR(Z_CACHE_SLOT_P(default_value))) || EG(exception))) {
47464746
HANDLE_EXCEPTION();
47474747
}
47484748
}

Zend/zend_vm_execute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RECV_SPEC_HANDLER(ZEND_OPCODE_
11881188
zval *param = _get_zval_ptr_cv_undef_BP_VAR_W(execute_data, opline->result.var);
11891189

11901190
SAVE_OPLINE();
1191-
if (UNEXPECTED(!zend_verify_arg_type(EX(func), arg_num, param, NULL, CACHE_ADDR(opline->op2.num)))) {
1191+
if (UNEXPECTED(!zend_verify_arg_type(EX(func), arg_num, param, NULL, CACHE_ADDR(opline->op2.num)) || EG(exception))) {
11921192
HANDLE_EXCEPTION();
11931193
}
11941194
}
@@ -2208,7 +2208,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RECV_INIT_SPEC_CONST_HANDLER(Z
22082208
zval *default_value = EX_CONSTANT(opline->op2);
22092209

22102210
SAVE_OPLINE();
2211-
if (UNEXPECTED(!zend_verify_arg_type(EX(func), arg_num, param, default_value, CACHE_ADDR(Z_CACHE_SLOT_P(default_value))))) {
2211+
if (UNEXPECTED(!zend_verify_arg_type(EX(func), arg_num, param, default_value, CACHE_ADDR(Z_CACHE_SLOT_P(default_value))) || EG(exception))) {
22122212
HANDLE_EXCEPTION();
22132213
}
22142214
}

0 commit comments

Comments
 (0)