Skip to content

Add missing COMPILE_IGNORE_OTHER_FILES check for static calls #13986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
Loading