Skip to content

Commit 3364858

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #78903: Conflict in RTD key for closures results in crash
2 parents 05e6a11 + b55033f commit 3364858

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Zend/zend_compile.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6079,7 +6079,7 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo
60796079
}
60806080
/* }}} */
60816081

6082-
static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_ast_decl *decl, zend_bool toplevel) /* {{{ */
6082+
static int zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_ast_decl *decl, zend_bool toplevel) /* {{{ */
60836083
{
60846084
zend_string *unqualified_name, *name, *lcname, *key;
60856085
zend_op *opline;
@@ -6114,12 +6114,10 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
61146114
do_bind_function_error(lcname, op_array, 1);
61156115
}
61166116
zend_string_release_ex(lcname, 0);
6117-
return;
6117+
return SUCCESS;
61186118
}
61196119

61206120
key = zend_build_runtime_definition_key(lcname, decl->lex_pos);
6121-
zend_hash_update_ptr(CG(function_table), key, op_array);
6122-
61236121
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
61246122
opline = zend_emit_op_tmp(result, ZEND_DECLARE_LAMBDA_FUNCTION, NULL, NULL);
61256123
opline->extended_value = zend_alloc_cache_slot();
@@ -6134,6 +6132,8 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
61346132
zend_add_literal_string(&key);
61356133
}
61366134
zend_string_release_ex(lcname, 0);
6135+
6136+
return zend_hash_add_ptr(CG(function_table), key, op_array) != NULL ? SUCCESS : FAILURE;
61376137
}
61386138
/* }}} */
61396139

@@ -6179,7 +6179,13 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
61796179
zend_bool has_body = stmt_ast != NULL;
61806180
zend_begin_method_decl(op_array, decl->name, has_body);
61816181
} else {
6182-
zend_begin_func_decl(result, op_array, decl, toplevel);
6182+
if (zend_begin_func_decl(result, op_array, decl, toplevel) == FAILURE) {
6183+
/* A function with this RTD key is already registered.
6184+
* Fail gracefully by reusing the existing function. */
6185+
destroy_op_array(op_array);
6186+
return;
6187+
}
6188+
61836189
if (decl->kind == ZEND_AST_ARROW_FUNC) {
61846190
find_implicit_binds(&info, params_ast, stmt_ast);
61856191
compile_implicit_lexical_binds(&info, result, op_array);

0 commit comments

Comments
 (0)