Skip to content

Commit 3280209

Browse files
committed
Addirional fix for bug #78918
1 parent 20ef51d commit 3280209

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

Zend/zend_API.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,7 @@ ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *or
27622762
ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce, int persistent) /* {{{ */
27632763
{
27642764
zend_string *lcname;
2765+
zval zv, *ret;
27652766

27662767
/* TODO: Move this out of here in 7.4. */
27672768
if (persistent && EG(current_module) && EG(current_module)->type == MODULE_TEMPORARY) {
@@ -2779,9 +2780,11 @@ ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zen
27792780
zend_assert_valid_class_name(lcname);
27802781

27812782
lcname = zend_new_interned_string(lcname);
2782-
ce = zend_hash_add_ptr(CG(class_table), lcname, ce);
2783+
2784+
ZVAL_ALIAS_PTR(&zv, ce);
2785+
ret = zend_hash_add(CG(class_table), lcname, &zv);
27832786
zend_string_release_ex(lcname, 0);
2784-
if (ce) {
2787+
if (ret) {
27852788
if (!(ce->ce_flags & ZEND_ACC_IMMUTABLE)) {
27862789
ce->refcount++;
27872790
}

Zend/zend_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ struct _zend_ast_ref {
427427
/* internal types */
428428
#define IS_INDIRECT 13
429429
#define IS_PTR 14
430+
#define IS_ALIAS_PTR 15
430431
#define _IS_ERROR 15
431432

432433
/* fake types used only for type hinting (Z_TYPE(zv) can not use them) */
@@ -964,6 +965,11 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
964965
Z_TYPE_INFO_P(z) = IS_PTR; \
965966
} while (0)
966967

968+
#define ZVAL_ALIAS_PTR(z, p) do { \
969+
Z_PTR_P(z) = (p); \
970+
Z_TYPE_INFO_P(z) = IS_ALIAS_PTR; \
971+
} while (0)
972+
967973
#define ZVAL_ERROR(z) do { \
968974
Z_TYPE_INFO_P(z) = _IS_ERROR; \
969975
} while (0)

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,7 +3259,7 @@ static void preload_move_user_classes(HashTable *src, HashTable *dst)
32593259
}
32603260
}
32613261
if (copy) {
3262-
_zend_hash_append_ptr(dst, p->key, ce);
3262+
_zend_hash_append(dst, p->key, &p->val);
32633263
} else {
32643264
orig_dtor(&p->val);
32653265
}
@@ -4238,7 +4238,7 @@ static void preload_load(void)
42384238
Bucket *end = p + ZCSG(preload_script)->script.class_table.nNumUsed;
42394239

42404240
for (; p != end; p++) {
4241-
_zend_hash_append_ptr_ex(CG(class_table), p->key, Z_PTR(p->val), 1);
4241+
_zend_hash_append_ex(CG(class_table), p->key, &p->val, 1);
42424242
}
42434243
}
42444244

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
interface I {}
3+
class B implements I {}
4+
class_alias('B', 'C');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #78918.2: Class alias during preloading causes assertion failure
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload_class_alias_2.inc
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
var_dump(class_exists('B'));
13+
var_dump(class_exists('C'));
14+
?>
15+
--EXPECT--
16+
bool(true)
17+
bool(true)

ext/opcache/zend_persist.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,11 @@ static void zend_accel_persist_class_table(HashTable *class_table)
10371037
zend_accel_store_interned_string(p->key);
10381038
zend_persist_class_entry(&p->val);
10391039
} ZEND_HASH_FOREACH_END();
1040-
ZEND_HASH_FOREACH_PTR(class_table, ce) {
1041-
zend_update_parent_ce(ce);
1040+
ZEND_HASH_FOREACH_BUCKET(class_table, p) {
1041+
if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) {
1042+
ce = Z_PTR(p->val);
1043+
zend_update_parent_ce(ce);
1044+
}
10421045
} ZEND_HASH_FOREACH_END();
10431046
}
10441047

0 commit comments

Comments
 (0)