From 4bb66ddc7630be6467e7ad5b67250fd34c70017a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 16 Aug 2021 15:53:12 +0200 Subject: [PATCH] Set EG(active)=0 during preloading shutdown 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. --- Zend/zend_inheritance.c | 5 +++-- ext/opcache/ZendAccelerator.c | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index cadfc648d75..a6512657223 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -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); @@ -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; } diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index f1d090cf0b0..602b817c21b 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -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);