mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
Prevents goto
out of a finally block
This commit is contained in:
parent
018395efaf
commit
0312d0a262
3 changed files with 54 additions and 0 deletions
17
Zend/tests/try_finally_005.phpt
Normal file
17
Zend/tests/try_finally_005.phpt
Normal file
|
@ -0,0 +1,17 @@
|
|||
--TEST--
|
||||
Finally with long goto
|
||||
--FILE--
|
||||
<?php
|
||||
function foo () {
|
||||
try {
|
||||
} finally {
|
||||
goto label;
|
||||
}
|
||||
label:
|
||||
return 1;
|
||||
}
|
||||
|
||||
foo();
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: 'goto' out of a finally block is disallowed in %stry_finally_005.php on line %d
|
18
Zend/tests/try_finally_006.phpt
Normal file
18
Zend/tests/try_finally_006.phpt
Normal file
|
@ -0,0 +1,18 @@
|
|||
--TEST--
|
||||
Finally with near goto
|
||||
--FILE--
|
||||
<?php
|
||||
function foo () {
|
||||
try {
|
||||
} finally {
|
||||
goto label;
|
||||
echo "dummy";
|
||||
label:
|
||||
echo "label";
|
||||
}
|
||||
}
|
||||
|
||||
foo();
|
||||
?>
|
||||
--EXPECTF--
|
||||
label
|
|
@ -2277,6 +2277,25 @@ void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2
|
|||
zval_dtor(label);
|
||||
Z_TYPE_P(label) = IS_NULL;
|
||||
|
||||
if (op_array->last_try_catch) {
|
||||
zend_uint i, op_num = opline - CG(active_op_array)->opcodes;
|
||||
for (i=0; i<op_array->last_try_catch; i++) {
|
||||
if (op_array->try_catch_array[i].try_op > op_num) {
|
||||
break;
|
||||
}
|
||||
if (op_num >= op_array->try_catch_array[i].finally_op) {
|
||||
zend_op *p, *end;
|
||||
p = opline;
|
||||
end = op_array->opcodes + opline->op1.opline_num;
|
||||
while (++p < end) {
|
||||
if (p->opcode == ZEND_LEAVE) {
|
||||
zend_error(E_COMPILE_ERROR, "'goto' out of a finally block is disallowed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that we are not moving into loop or switch */
|
||||
current = opline->extended_value;
|
||||
for (distance = 0; current != dest->brk_cont; distance++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue