Skip to content

Commit 9ce1a36

Browse files
committed
Fixed segfault with empty break
1 parent 629c1ec commit 9ce1a36

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

Zend/tests/try_finally_011.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Try finally (segfault with empty break)
3+
--FILE--
4+
<?php
5+
function foo () {
6+
try {
7+
break;
8+
} finally {
9+
}
10+
}
11+
12+
foo();
13+
?>
14+
--EXPECTF--
15+
Fatal error: Cannot break/continue 1 level in %stry_finally_011.php on line %d

Zend/zend_opcode.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,16 @@ static void zend_resolve_finally_calls(zend_op_array *op_array TSRMLS_DC)
643643
zend_brk_cont_element *jmp_to;
644644

645645
nest_levels = Z_LVAL(op_array->literals[opline->op2.constant].constant);
646-
array_offset = opline->op1.opline_num;
647-
do {
648-
jmp_to = &op_array->brk_cont_array[array_offset];
649-
if (nest_levels > 1) {
650-
array_offset = jmp_to->parent;
651-
}
652-
} while (--nest_levels > 0);
653-
zend_resolve_finally_call(op_array, i, opline->opcode == ZEND_BRK ? jmp_to->brk : jmp_to->cont TSRMLS_CC);
654-
break;
646+
if ((array_offset = opline->op1.opline_num) != -1) {
647+
do {
648+
jmp_to = &op_array->brk_cont_array[array_offset];
649+
if (nest_levels > 1) {
650+
array_offset = jmp_to->parent;
651+
}
652+
} while (--nest_levels > 0);
653+
zend_resolve_finally_call(op_array, i, opline->opcode == ZEND_BRK ? jmp_to->brk : jmp_to->cont TSRMLS_CC);
654+
break;
655+
}
655656
}
656657
case ZEND_GOTO:
657658
if (Z_TYPE(op_array->literals[opline->op2.constant].constant) != IS_LONG) {

0 commit comments

Comments
 (0)