Skip to content

Commit ee45dba

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Addirional fix for bug #78918
2 parents 8fb3ef6 + 3280209 commit ee45dba

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
@@ -2581,6 +2581,7 @@ ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *or
25812581
ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce, int persistent) /* {{{ */
25822582
{
25832583
zend_string *lcname;
2584+
zval zv, *ret;
25842585

25852586
/* TODO: Move this out of here in 7.4. */
25862587
if (persistent && EG(current_module) && EG(current_module)->type == MODULE_TEMPORARY) {
@@ -2598,9 +2599,11 @@ ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zen
25982599
zend_assert_valid_class_name(lcname);
25992600

26002601
lcname = zend_new_interned_string(lcname);
2601-
ce = zend_hash_add_ptr(CG(class_table), lcname, ce);
2602+
2603+
ZVAL_ALIAS_PTR(&zv, ce);
2604+
ret = zend_hash_add(CG(class_table), lcname, &zv);
26022605
zend_string_release_ex(lcname, 0);
2603-
if (ce) {
2606+
if (ret) {
26042607
if (!(ce->ce_flags & ZEND_ACC_IMMUTABLE)) {
26052608
ce->refcount++;
26062609
}

Zend/zend_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ struct _zend_ast_ref {
541541
/* internal types */
542542
#define IS_INDIRECT 15
543543
#define IS_PTR 16
544+
#define IS_ALIAS_PTR 17
544545
#define _IS_ERROR 17
545546

546547
/* used for casts */
@@ -1075,6 +1076,11 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
10751076
Z_TYPE_INFO_P(z) = IS_PTR; \
10761077
} while (0)
10771078

1079+
#define ZVAL_ALIAS_PTR(z, p) do { \
1080+
Z_PTR_P(z) = (p); \
1081+
Z_TYPE_INFO_P(z) = IS_ALIAS_PTR; \
1082+
} while (0)
1083+
10781084
#define ZVAL_ERROR(z) do { \
10791085
Z_TYPE_INFO_P(z) = _IS_ERROR; \
10801086
} while (0)

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,7 +3323,7 @@ static void preload_move_user_classes(HashTable *src, HashTable *dst)
33233323
}
33243324
}
33253325
if (copy) {
3326-
_zend_hash_append_ptr(dst, p->key, ce);
3326+
_zend_hash_append(dst, p->key, &p->val);
33273327
} else {
33283328
orig_dtor(&p->val);
33293329
}
@@ -4332,7 +4332,7 @@ static void preload_load(void)
43324332
Bucket *end = p + ZCSG(preload_script)->script.class_table.nNumUsed;
43334333

43344334
for (; p != end; p++) {
4335-
_zend_hash_append_ptr_ex(CG(class_table), p->key, Z_PTR(p->val), 1);
4335+
_zend_hash_append_ex(CG(class_table), p->key, &p->val, 1);
43364336
}
43374337
}
43384338

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
@@ -1080,8 +1080,11 @@ static void zend_accel_persist_class_table(HashTable *class_table)
10801080
zend_accel_store_interned_string(p->key);
10811081
zend_persist_class_entry(&p->val);
10821082
} ZEND_HASH_FOREACH_END();
1083-
ZEND_HASH_FOREACH_PTR(class_table, ce) {
1084-
zend_update_parent_ce(ce);
1083+
ZEND_HASH_FOREACH_BUCKET(class_table, p) {
1084+
if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) {
1085+
ce = Z_PTR(p->val);
1086+
zend_update_parent_ce(ce);
1087+
}
10851088
} ZEND_HASH_FOREACH_END();
10861089
}
10871090

0 commit comments

Comments
 (0)