com php-src: Fixed bug #71092 (Segmentation fault with return type hinting): NEWS Zend/tests/return_types/029.phpt Zen
d/tests/return_types/bug71092.phpt Zend/zend_ compile.c
| From: | Xinchen Hui | Date: | Fri, 11 Dec 2015 17:11:28 +0000 |
| Subject: | com php-src: Fixed bug #71092 (Segmentation fault with return type hinting): NEWS Zend/tests/return_types/029.phpt Zen d/tests/return_types/bug71092.phpt Zend/zend_ compile.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90237@lists.php.net to get a copy of this message | ||
Commit: 778e5f3da50cacb0ab04944863d3de6999dae3e3
Author: Xinchen Hui <laruence@gmail.com> Fri, 11 Dec 2015 09:11:28 -0800
Parents: 04407b79dfa41a38a6bce3823b3f80eab9ce3ae8
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=778e5f3da50cacb0ab04944863d3de6999dae3e3
Log:
Fixed bug #71092 (Segmentation fault with return type hinting)
Bugs:
https://bugs.php.net/71092
Changed paths:
M NEWS
A Zend/tests/return_types/029.phpt
A Zend/tests/return_types/bug71092.phpt
M Zend/zend_compile.c
Diff:
diff --git a/NEWS b/NEWS
index 6f2b4b2..54bdeb7 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PHP NEWS
?? Jan 2016 PHP 7.0.2
- Core:
+ . Fixed bug #71092 (Segmentation fault with return type hinting). (Laruence)
. Fixed bug memleak in header_register_callback. (Laruence)
. Fixed bug #71067 (Local object in class method stays in memory for each
call). (Laruence)
diff --git a/Zend/tests/return_types/029.phpt b/Zend/tests/return_types/029.phpt
new file mode 100644
index 0000000..011182d
--- /dev/null
+++ b/Zend/tests/return_types/029.phpt
@@ -0,0 +1,23 @@
+--TEST--
+return type with finally
+--INI--
+opcache.enable=0
+--FILE--
+<?php
+
+function foo() : array {
+ try {
+ throw new Exception("xxxx");
+ } finally {
+ return ;
+ }
+}
+
+foo();
+?>
+--EXPECTF--
+Fatal error: Uncaught TypeError: Return value of foo() must be of the type array, none returned in
%s29.php:%d
+Stack trace:
+#0 %s(%d): foo()
+#1 {main}
+ thrown in %s029.php on line %d
diff --git a/Zend/tests/return_types/bug71092.phpt b/Zend/tests/return_types/bug71092.phpt
new file mode 100644
index 0000000..a1ebc79
--- /dev/null
+++ b/Zend/tests/return_types/bug71092.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #71092 (Segmentation fault with return type hinting)
+--INI--
+opcache.enable=0
+--FILE--
+<?php
+
+function boom(): array {
+ $data = [['id']];
+ switch ($data[0]) {
+ case ['id']:
+ return;
+ }
+}
+
+boom();
+?>
+--EXPECTF--
+Fatal error: Uncaught TypeError: Return value of boom() must be of the type array, none returned in
%sbug71092.php:%d
+Stack trace:
+#0 %s(%d): boom()
+#1 {main}
+ thrown in %sbug71092.php on line %d
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 34246bd...1609ba5 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3583,8 +3583,6 @@ void zend_compile_return(zend_ast *ast) /* {{{ */
zend_compile_expr(&expr_node, expr_ast);
}
- zend_handle_loops_and_finally();
-
if (CG(context).in_finally) {
opline = zend_emit_op(NULL, ZEND_DISCARD_EXCEPTION, NULL, NULL);
opline->op1_type = IS_TMP_VAR;
@@ -3595,6 +3593,9 @@ void zend_compile_return(zend_ast *ast) /* {{{ */
if (!(CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) &&
CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
zend_emit_return_type_check(expr_ast ? &expr_node : NULL, CG(active_op_array)->arg_info -
1);
}
+
+ zend_handle_loops_and_finally();
+
opline = zend_emit_op(NULL, by_ref ? ZEND_RETURN_BY_REF : ZEND_RETURN,
&expr_node, NULL);