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

Function uses global variable causes inconsistency in variable id #24

Open
quanyang opened this issue May 9, 2016 · 2 comments
Open

Comments

@quanyang
Copy link

quanyang commented May 9, 2016

Example:

<?php
$global = "B";
function TestTaintOnFunction() {
    global $global;
    $secondVar = "2";
    echo $global;
}

Results in:

    Expr_Assign
        var: Var#1<$global>
        expr: LITERAL('B')
        result: Var#2
    Stmt_Function<TestTaintOnFunction>

Function TestTaintOnFunction():
Block#1
    Terminal_GlobalVar
        var: LITERAL('global')
    Expr_Assign
        var: Var#1<$secondVar>
        expr: LITERAL('2')
        result: Var#2
    Terminal_Echo
        expr: Var#3<$global>

Anyway to make the id consistent?

@nikic
Copy link
Collaborator

nikic commented May 10, 2016

Something to consider here is that the pseudo-main scope of a file does not necessarily coincide with the global scope. Consider this scenario:

// file1.php
<?php
$global = "B";
function test() {
    global $global;
    echo $global;
}

// file2.php
<?php
$global = "A";
function run() {
    require __DIR__ . '/file1.php';
}
run();

And then execute file2.php. In this case the $global variable from file1.php will actually be a local variable inside the run function and global $global will instead reference the $global from file2.php. (Nowadays files are nearly always included from something other than the global scope due to autoloading, so this is not entirely idle speculation.)

@quanyang
Copy link
Author

Yes that could be a possibility. However, the currently php-cfg implementation is not be able to handle inclusion of external files, am I right?

Do you think it'd be possible at all to fix this issue for global vars?

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

No branches or pull requests

2 participants