Skip to content

Commit 8b1b68d

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #78926: Handle class table reallocation on failed link
2 parents 8988c49 + 32c1f37 commit 8b1b68d

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

Zend/tests/bug78926.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #78926: Segmentation fault on Symfony cache:clear
3+
--FILE--
4+
<?php
5+
6+
spl_autoload_register(function($class) {
7+
for ($i = 0; $i < 100; $i++) {
8+
eval("class C$i {}");
9+
}
10+
});
11+
12+
try {
13+
class B extends A {}
14+
} catch (Error $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
var_dump(class_exists('B', false));
18+
19+
?>
20+
--EXPECT--
21+
Class 'A' not found
22+
bool(false)

Zend/zend_compile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,8 @@ ZEND_API int do_bind_class(zval *lcname, zend_string *lc_parent_name) /* {{{ */
11181118
}
11191119

11201120
if (zend_do_link_class(ce, lc_parent_name) == FAILURE) {
1121+
/* Reload bucket pointer, the hash table may have been reallocated */
1122+
zv = zend_hash_find(EG(class_table), Z_STR_P(lcname));
11211123
zend_hash_set_bucket_key(EG(class_table), (Bucket *) zv, Z_STR_P(rtd_key));
11221124
return FAILURE;
11231125
}

Zend/zend_vm_def.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7086,6 +7086,8 @@ ZEND_VM_HANDLER(145, ZEND_DECLARE_CLASS_DELAYED, CONST, CONST)
70867086
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
70877087
} else {
70887088
if (zend_do_link_class(ce, Z_STR_P(RT_CONSTANT(opline, opline->op2))) == FAILURE) {
7089+
/* Reload bucket pointer, the hash table may have been reallocated */
7090+
zv = zend_hash_find(EG(class_table), Z_STR_P(lcname));
70897091
zend_hash_set_bucket_key(EG(class_table), (Bucket *) zv, Z_STR_P(lcname + 1));
70907092
HANDLE_EXCEPTION();
70917093
}
@@ -7111,7 +7113,6 @@ ZEND_VM_HANDLER(146, ZEND_DECLARE_ANON_CLASS, ANY, ANY, CACHE_SLOT)
71117113
if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
71127114
SAVE_OPLINE();
71137115
if (zend_do_link_class(ce, (OP2_TYPE == IS_CONST) ? Z_STR_P(RT_CONSTANT(opline, opline->op2)) : NULL) == FAILURE) {
7114-
zend_hash_set_bucket_key(EG(class_table), (Bucket *) zv, rtd_key);
71157116
HANDLE_EXCEPTION();
71167117
}
71177118
}

Zend/zend_vm_execute.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DECLARE_ANON_CLASS_SPEC_HANDLE
23662366
if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
23672367
SAVE_OPLINE();
23682368
if (zend_do_link_class(ce, (opline->op2_type == IS_CONST) ? Z_STR_P(RT_CONSTANT(opline, opline->op2)) : NULL) == FAILURE) {
2369-
zend_hash_set_bucket_key(EG(class_table), (Bucket *) zv, rtd_key);
23702369
HANDLE_EXCEPTION();
23712370
}
23722371
}
@@ -6229,6 +6228,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DECLARE_CLASS_DELAYED_SPEC_CON
62296228
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
62306229
} else {
62316230
if (zend_do_link_class(ce, Z_STR_P(RT_CONSTANT(opline, opline->op2))) == FAILURE) {
6231+
/* Reload bucket pointer, the hash table may have been reallocated */
6232+
zv = zend_hash_find(EG(class_table), Z_STR_P(lcname));
62326233
zend_hash_set_bucket_key(EG(class_table), (Bucket *) zv, Z_STR_P(lcname + 1));
62336234
HANDLE_EXCEPTION();
62346235
}

0 commit comments

Comments
 (0)