From 11d1f235a0ded4fd4ac64772be2e61e3711bb5e3 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 17 Apr 2024 14:09:08 +0200 Subject: [PATCH] Add missing COMPILE_IGNORE_OTHER_FILES check for static calls --- Zend/zend_compile.c | 47 +++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index cba90112cfc18..e7f9ed8f000a2 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3996,6 +3996,27 @@ static bool fbc_is_finalized(zend_function *fbc) { return !ZEND_USER_CODE(fbc->type) || (fbc->common.fn_flags & ZEND_ACC_DONE_PASS_TWO); } +static bool zend_compile_ignore_class(zend_class_entry *ce, zend_string *filename) +{ + if (ce->type == ZEND_INTERNAL_CLASS) { + return CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES; + } else { + return (CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) + && ce->info.user.filename != filename; + } +} + +static bool zend_compile_ignore_function(zend_function *fbc, zend_string *filename) +{ + if (fbc->type == ZEND_INTERNAL_FUNCTION) { + return CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS; + } else { + return (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS) + || ((CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) + && fbc->op_array.filename != filename); + } +} + static zend_result zend_try_compile_ct_bound_init_user_func(zend_ast *name_ast, uint32_t num_args) /* {{{ */ { zend_string *name, *lcname; @@ -4010,11 +4031,9 @@ static zend_result zend_try_compile_ct_bound_init_user_func(zend_ast *name_ast, lcname = zend_string_tolower(name); fbc = zend_hash_find_ptr(CG(function_table), lcname); - if (!fbc || !fbc_is_finalized(fbc) - || (fbc->type == ZEND_INTERNAL_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS)) - || (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS)) - || (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) && fbc->op_array.filename != CG(active_op_array)->filename) - ) { + if (!fbc + || !fbc_is_finalized(fbc) + || zend_compile_ignore_function(fbc, CG(active_op_array)->filename)) { zend_string_release_ex(lcname, 0); return FAILURE; } @@ -4538,11 +4557,9 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{ return; } - if (!fbc || !fbc_is_finalized(fbc) - || (fbc->type == ZEND_INTERNAL_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS)) - || (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS)) - || (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) && fbc->op_array.filename != CG(active_op_array)->filename) - ) { + if (!fbc + || !fbc_is_finalized(fbc) + || zend_compile_ignore_function(fbc, CG(active_op_array)->filename)) { zend_string_release_ex(lcname, 0); zend_compile_dynamic_call(result, &name_node, args_ast, ast->lineno); return; @@ -4709,7 +4726,11 @@ static void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type if (opline->op1_type == IS_CONST) { zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op1) + 1); ce = zend_hash_find_ptr(CG(class_table), lcname); - if (!ce && CG(active_class_entry) + if (ce) { + if (zend_compile_ignore_class(ce, CG(active_op_array)->filename)) { + ce = NULL; + } + } else if (CG(active_class_entry) && zend_string_equals_ci(CG(active_class_entry)->name, lcname)) { ce = CG(active_class_entry); } @@ -7990,9 +8011,7 @@ static void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel) ce->parent_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); if (parent_ce - && ((parent_ce->type != ZEND_INTERNAL_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES)) - && ((parent_ce->type != ZEND_USER_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) || (parent_ce->info.user.filename == ce->info.user.filename))) { - + && !zend_compile_ignore_class(parent_ce, ce->info.user.filename)) { if (zend_try_early_bind(ce, parent_ce, lcname, NULL)) { zend_string_release(lcname); return;