Skip to content
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

Fix get_function_or_method_name when included file is scoped #8467

Merged

Conversation

vajexal
Copy link
Contributor

@vajexal vajexal commented Apr 30, 2022

get_function_or_method_name causes segfault when called on scoped included file (require or include from class method)

How to reproduce:

we'll need one extra php function

PHP_FUNCTION(get_current_function_name) {
    ZEND_PARSE_PARAMETERS_NONE();

    zend_string *function_name = get_function_or_method_name(EG(current_execute_data)->prev_execute_data->func);

    RETURN_STR(function_name);
}

// a.php

class Foo
{
    public static function bar()
    {
        return require 'b.php';
    }
}

var_dump(Foo::bar());
// b.php

return [
    'foo' => get_current_function_name(),
];

@kocsismate
Copy link
Member

IMO this should be fixed in earlier branches as well

@vajexal vajexal changed the base branch from master to PHP-8.0 May 1, 2022 10:34
@vajexal vajexal changed the base branch from PHP-8.0 to master May 1, 2022 10:35
@vajexal vajexal force-pushed the bugfix/get-function-or-method-name-fix branch from 3a258f7 to 5081aa0 Compare May 1, 2022 11:09
@vajexal vajexal changed the base branch from master to PHP-8.0 May 1, 2022 11:10
@cmb69
Copy link
Contributor

cmb69 commented May 2, 2022

It might make sense to add a respective regression test. The required userland function could be defined in ext/zend_test.

Copy link
Contributor

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, and adding the regression test. There is a minor issue regarding PHP-8.0; other than that, the patch looks good.

ext/zend_test/tests/get_function_or_method_name_01.phpt Outdated Show resolved Hide resolved
@vajexal vajexal force-pushed the bugfix/get-function-or-method-name-fix branch from 31d76fe to ce0459d Compare May 3, 2022 14:00
@kocsismate kocsismate merged commit 74924ad into php:PHP-8.0 May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants