File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ PHP NEWS
17
17
delegated Generator). (Arnaud)
18
18
. Fixed bug GH-19326 (Calling Generator::throw() on a running generator with
19
19
a non-Generator delegate crashes). (Arnaud)
20
+ . Fixed bug GH-18736 (Circumvented type check with return by ref + finally).
21
+ (ilutov)
20
22
21
23
- FTP:
22
24
. Fix theoretical issues with hrtime() not being available. (nielsdos)
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-18736: Circumvented type check with return by ref + finally
3
+ --FILE--
4
+ <?php
5
+
6
+ function &test (): int {
7
+ $ x = 0 ;
8
+ try {
9
+ return $ x ;
10
+ } finally {
11
+ $ x = 'test ' ;
12
+ }
13
+ }
14
+
15
+ try {
16
+ $ x = &test ();
17
+ var_dump ($ x );
18
+ } catch (Error $ e ) {
19
+ echo $ e ->getMessage (), "\n" ;
20
+ }
21
+
22
+ ?>
23
+ --EXPECT--
24
+ test(): Return value must be of type int, string returned
Original file line number Diff line number Diff line change @@ -5201,8 +5201,20 @@ static void zend_compile_return(zend_ast *ast) /* {{{ */
5201
5201
expr_ast ? & expr_node : NULL , CG (active_op_array )-> arg_info - 1 , 0 );
5202
5202
}
5203
5203
5204
+ uint32_t opnum_before_finally = get_next_op_number ();
5205
+
5204
5206
zend_handle_loops_and_finally ((expr_node .op_type & (IS_TMP_VAR | IS_VAR )) ? & expr_node : NULL );
5205
5207
5208
+ /* Content of reference might have changed in finally, repeat type check. */
5209
+ if (by_ref
5210
+ /* Check if any opcodes were emitted since the last return type check. */
5211
+ && opnum_before_finally != get_next_op_number ()
5212
+ && !is_generator
5213
+ && (CG (active_op_array )-> fn_flags & ZEND_ACC_HAS_RETURN_TYPE )) {
5214
+ zend_emit_return_type_check (
5215
+ expr_ast ? & expr_node : NULL , CG (active_op_array )-> arg_info - 1 , 0 );
5216
+ }
5217
+
5206
5218
opline = zend_emit_op (NULL , by_ref ? ZEND_RETURN_BY_REF : ZEND_RETURN ,
5207
5219
& expr_node , NULL );
5208
5220
You can’t perform that action at this time.
0 commit comments