Skip to content

Commit

Permalink
Set EG(active)=0 during preloading shutdown
Browse files Browse the repository at this point in the history
Just like during normal shutdown, we should set EG(active)=0
during the partial preloading shutdown, to make sure that no
user code can run.

We need to slightly tweak inheritance class loading to still
pick the right code path.
  • Loading branch information
nikic committed Aug 16, 2021
1 parent 99ddc80 commit 4bb66dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ static zend_always_inline void register_unresolved_class(zend_string *name) {
static zend_class_entry *lookup_class_ex(
zend_class_entry *scope, zend_string *name, bool register_unresolved) {
zend_class_entry *ce;
bool in_preload = CG(compiler_options) & ZEND_COMPILE_PRELOAD;

if (UNEXPECTED(!EG(active))) {
if (UNEXPECTED(!EG(active) && !in_preload)) {
zend_string *lc_name = zend_string_tolower(name);

ce = zend_hash_find_ptr(CG(class_table), lc_name);
Expand All @@ -248,7 +249,7 @@ static zend_class_entry *lookup_class_ex(
ce = zend_lookup_class_ex(
name, NULL, ZEND_FETCH_CLASS_ALLOW_UNLINKED | ZEND_FETCH_CLASS_NO_AUTOLOAD);

if (!CG(in_compilation) || (CG(compiler_options) & ZEND_COMPILE_PRELOAD)) {
if (!CG(in_compilation) || in_preload) {
if (ce) {
return ce;
}
Expand Down
2 changes: 2 additions & 0 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4448,6 +4448,8 @@ static int accel_preload(const char *config, bool in_child)
php_output_end_all();
php_free_shutdown_functions();

EG(active) = 0;

/* Release stored values to avoid dangling pointers */
zend_hash_graceful_reverse_destroy(&EG(symbol_table));
zend_hash_init(&EG(symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);
Expand Down

0 comments on commit 4bb66dd

Please sign in to comment.