com php-src: Only allow single comma in tail: Zend/tests/list _013.phpt Zend/zend_ast.h Zend/zend_compile .c
| From: | Xinchen Hui | Date: | Tue, 14 Jun 2016 06:02:34 +0000 |
| Subject: | com php-src: Only allow single comma in tail: Zend/tests/list _013.phpt Zend/zend_ast.h Zend/zend_compile .c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92377@lists.php.net to get a copy of this message | ||
Commit: 9c8e1c03b97fea34432ed8a91e8ddd9b9d20a649
Author: Xinchen Hui <laruence@gmail.com> Tue, 14 Jun 2016 14:02:34 +0800
Parents: 14e790a0753dce4dfaeff1b2d8f9800b519917c1
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9c8e1c03b97fea34432ed8a91e8ddd9b9d20a649
Log:
Only allow single comma in tail
Changed paths:
A Zend/tests/list_013.phpt
M Zend/zend_ast.h
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/list_013.phpt b/Zend/tests/list_013.phpt
new file mode 100644
index 0000000..2869f5f
--- /dev/null
+++ b/Zend/tests/list_013.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Disallow tail empty elements in normal arrays
+--FILE--
+<?php
+
+var_dump([1, 2, ,]);
+
+?>
+--EXPECTF--
+Fatal error: Cannot use empty array elements in arrays in %s on line %d
diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h
index 3efadf7..de67c50 100644
--- a/Zend/zend_ast.h
+++ b/Zend/zend_ast.h
@@ -268,7 +268,7 @@ static zend_always_inline zend_ast *zend_ast_create_cast(uint32_t type, zend_ast
}
static zend_always_inline void zend_ast_list_rtrim(zend_ast *ast) {
zend_ast_list *list = zend_ast_get_list(ast);
- while (list->children && list->child[list->children - 1] == NULL) {
+ if (list->children && list->child[list->children - 1] == NULL) {
list->children--;
}
}
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 63bd813..962f2ee 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2762,10 +2762,7 @@ static void zend_verify_list_assign_target(zend_ast *var_ast, zend_bool
old_styl
static void zend_compile_unkeyed_list_assign(zend_ast_list *list, znode *expr_node, zend_bool
old_style) /* {{{ */
{
uint32_t i;
-
- if (list->children == 0) {
- zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
- }
+ zend_bool has_elems = 0;
for (i = 0; i < list->children; ++i) {
zend_ast *elem_ast = list->child[i];
@@ -2780,6 +2777,7 @@ static void zend_compile_unkeyed_list_assign(zend_ast_list *list, znode
*expr_no
}
var_ast = elem_ast->child[0];
+ has_elems = 1;
dim_node.op_type = IS_CONST;
ZVAL_LONG(&dim_node.u.constant, i);
@@ -2797,6 +2795,11 @@ static void zend_compile_unkeyed_list_assign(zend_ast_list *list, znode
*expr_no
zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
zend_emit_assign_znode(var_ast, &fetch_result);
}
+
+ if (has_elems == 0) {
+ zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
+ }
+
}
/* }}} */