Skip to content

Commit da54751

Browse files
committed
C++: Add testcase that demonstrate the need for self-flow out of indirect parameters.
1 parent fe97572 commit da54751

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ postWithInFlow
6767
| ref.cpp:109:9:109:11 | val [post update] | PostUpdateNode should not be the target of local flow. |
6868
| ref.cpp:113:11:113:13 | val [post update] | PostUpdateNode should not be the target of local flow. |
6969
| ref.cpp:115:11:115:13 | val [post update] | PostUpdateNode should not be the target of local flow. |
70+
| self_parameter_flow.cpp:3:4:3:5 | ps [inner post update] | PostUpdateNode should not be the target of local flow. |
71+
| self_parameter_flow.cpp:8:9:8:9 | s [inner post update] | PostUpdateNode should not be the target of local flow. |
7072
| test.cpp:91:3:91:9 | source1 [post update] | PostUpdateNode should not be the target of local flow. |
7173
| test.cpp:115:3:115:6 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
7274
| test.cpp:115:4:115:6 | out [inner post update] | PostUpdateNode should not be the target of local flow. |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
void incr(unsigned char **ps) // $ ast-def=ps ir-def=*ps ir-def=**ps
2+
{
3+
*ps += 1;
4+
}
5+
6+
void callincr(unsigned char *s) // $ ast-def=s
7+
{
8+
incr(&s);
9+
}
10+
11+
void test(unsigned char *s) // $ ast-def=s
12+
{
13+
callincr(s); // $ MISSING: flow
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import cpp
2+
import semmle.code.cpp.dataflow.new.DataFlow
3+
import TestUtilities.InlineExpectationsTest
4+
5+
module TestConfig implements DataFlow::ConfigSig {
6+
predicate isSource(DataFlow::Node source) {
7+
source.getLocation().getFile().getBaseName() = "self_parameter_flow.cpp" and
8+
source.asIndirectArgument() =
9+
any(Call call | call.getTarget().hasName("callincr")).getAnArgument()
10+
}
11+
12+
predicate isSink(DataFlow::Node sink) {
13+
sink.asDefiningArgument() =
14+
any(Call call | call.getTarget().hasName("callincr")).getAnArgument()
15+
}
16+
}
17+
18+
import DataFlow::Global<TestConfig>
19+
20+
module TestSelfParameterFlow implements TestSig {
21+
string getARelevantTag() { result = "flow" }
22+
23+
predicate hasActualResult(Location location, string element, string tag, string value) {
24+
exists(DataFlow::Node sink |
25+
flowTo(sink) and
26+
location = sink.getLocation() and
27+
element = sink.toString() and
28+
tag = "flow" and
29+
value = ""
30+
)
31+
}
32+
}
33+
34+
import MakeTest<TestSelfParameterFlow>

0 commit comments

Comments
 (0)