Skip to content

Commit 9f81c56

Browse files
committed
Fix out-of-bounds read in array compilation
UNPACK elements only have one child. Don't access the second one until we have excluded this case.
1 parent 7632a41 commit 9f81c56

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Zend/zend_compile.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7032,7 +7032,7 @@ static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
70327032
for (i = 0; i < list->children; ++i) {
70337033
zend_ast *elem_ast = list->child[i];
70347034
zend_ast *value_ast = elem_ast->child[0];
7035-
zend_ast *key_ast = elem_ast->child[1];
7035+
zend_ast *key_ast;
70367036

70377037
zval *value = zend_ast_get_zval(value_ast);
70387038
if (elem_ast->kind == ZEND_AST_UNPACK) {
@@ -7060,6 +7060,7 @@ static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
70607060

70617061
Z_TRY_ADDREF_P(value);
70627062

7063+
key_ast = elem_ast->child[1];
70637064
if (key_ast) {
70647065
zval *key = zend_ast_get_zval(key_ast);
70657066
switch (Z_TYPE_P(key)) {
@@ -7823,8 +7824,6 @@ void zend_compile_array(znode *result, zend_ast *ast) /* {{{ */
78237824
}
78247825

78257826
value_ast = elem_ast->child[0];
7826-
key_ast = elem_ast->child[1];
7827-
by_ref = elem_ast->attr;
78287827

78297828
if (elem_ast->kind == ZEND_AST_UNPACK) {
78307829
zend_compile_expr(&value_node, value_ast);
@@ -7836,6 +7835,9 @@ void zend_compile_array(znode *result, zend_ast *ast) /* {{{ */
78367835
continue;
78377836
}
78387837

7838+
key_ast = elem_ast->child[1];
7839+
by_ref = elem_ast->attr;
7840+
78397841
if (key_ast) {
78407842
zend_compile_expr(&key_node, key_ast);
78417843
zend_handle_numeric_op(&key_node);

0 commit comments

Comments
 (0)