github / github/codeql

[C++] Control Flow Influence not detected interprocedurally

Open
#18,100 5 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

The `controls` predicate from `GuardCondition` does not detect influence across function boundaries. Is this intended behavior?

Here is the code for my example. Influence from `condition` in line 23 is detected but not from line 14.

Similarly the influence on `call()` in line 30 is detected but not on line 8.

```cpp
#include

void call()
{
}

void call_wrapper()
{
call(); // not detected as controlled
}

void check_condition(bool condition)
{
if (condition) // not detected as controlling
{
throw std::exception();
}
}

void my_fn(bool outer, bool condition)
{

if (condition) // detected as controlling
{
throw std::exception();
}

check_condition(condition);

call(); // detected as controlled

call_wrapper();
}
```

```ql
import cpp
import semmle.code.cpp.controlflow.IRGuards

from Variable v, VariableAccess va, GuardCondition cond, Call c, int line
where
c.getTarget().getName() = "call" and
va.getTarget() = v and
v.getName() = "condition" and
cond.getAChild*() = va and
cond.controls(c.getBasicBlock(), _) and
line = va.getLocation().getStartLine()
select v, va, cond, c, line

```

```
| v | va | cond | c | line |
+-----------+-----------+-----------+--------------+------+
| condition | condition | condition | call to call | 23 |
```

CodeQL version: 2.19.3

Contributor guide

Open the contributing guide

Research direction

Reproduce the example query and inspect semmle.code.cpp.controlflow.IRGuards, especially GuardCondition.controls and its interprocedural behavior. Compare the reported results at the marked call and condition lines, then check existing control-flow tests. Done means the intended behavior is established and covered by an appropriate regression test or documented as unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.