X Tutup
The Wayback Machine - https://web.archive.org/web/20220707015619/https://github.com/github/codeql/issues/9787
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

C++ Initializer Inconsistencies #9787

Open
bdrodes opened this issue Jul 6, 2022 · 0 comments
Open

C++ Initializer Inconsistencies #9787

bdrodes opened this issue Jul 6, 2022 · 0 comments
Labels
question

Comments

@bdrodes
Copy link

@bdrodes bdrodes commented Jul 6, 2022

Below is a simple C++ file illustrating two uses of codeql Initializer .

#include <iostream>
#include <cstdlib>

using namespace std;
int main()
{
    char* test1 = "hello world";
    if(char* test2 = (char*)malloc(10))
    {
        cout<<"test"<<endl;
    }
}

This example illustrates a few inconsistencies in how Initializer logic functions.

The first issue is that the initializer expression does not appear to be a child of the if condition expression. The following query will yield no result.

/**
 * @kind problem
 */
import cpp

from Initializer i, IfStmt ifs
where ifs.getControllingExpr().getAChild*() = i.getExpr()
select i, "TEST"

The second issue, which is more minor and potentially not an issue is the query below will find that test2 is an access of itself, whereas test1 is not an access. This may be expected however, since test2 is first assigned, then result evaluated by the if conditional. I'm not entirely sure if that's what is going on here though.

/**
 * @kind problem
 */
import cpp

from Variable v, Expr e
where 
e = v.getAnAccess()
select e, "TEST"
@bdrodes bdrodes added the question label Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question
Projects
None yet
Development

No branches or pull requests

1 participant
X Tutup