Skip to content

Commit ac70bb3

Browse files
committed
Don't populate CE_CACHE during compilation
It's possible for CE_CACHE slots to be populated during compilation (e.g. due to an early binding attempt). When opcache then persists the class, it clears the CE_CACHE slot for the class name as declared, but not for different spellings (that only differ in case). As such, a pointer to the old, non-persistent class entry may be retained. Fix this by not populating CE_CACHE if in_compilation is set. Closes GH-7542.
1 parent 066f543 commit ac70bb3

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Zend/zend_execute_API.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,10 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
10751075
}
10761076
return NULL;
10771077
}
1078-
if (ZSTR_HAS_CE_CACHE(name)) {
1078+
/* Don't populate CE_CACHE for mutable classes during compilation.
1079+
* The class may be freed while persisting. */
1080+
if (ZSTR_HAS_CE_CACHE(name) &&
1081+
(!CG(in_compilation) || (ce->ce_flags & ZEND_ACC_IMMUTABLE))) {
10791082
ZSTR_SET_CE_CACHE(name, ce);
10801083
}
10811084
return ce;
@@ -1131,6 +1134,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
11311134
zend_string_release_ex(lc_name, 0);
11321135
}
11331136
if (ce) {
1137+
ZEND_ASSERT(!CG(in_compilation));
11341138
if (ZSTR_HAS_CE_CACHE(name)) {
11351139
ZSTR_SET_CE_CACHE(name, ce);
11361140
}

ext/opcache/zend_persist.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,6 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce)
868868
ce->inheritance_cache = NULL;
869869

870870
if (!(ce->ce_flags & ZEND_ACC_CACHED)) {
871-
if (ZSTR_HAS_CE_CACHE(ce->name)) {
872-
ZSTR_SET_CE_CACHE(ce->name, NULL);
873-
}
874871
zend_accel_store_interned_string(ce->name);
875872
if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS)
876873
&& !ZCG(current_persistent_script)->corrupted) {

0 commit comments

Comments
 (0)