Skip to content

Commit f65fe34

Browse files
committed
C++: Add false positive caused by flowing back into a function after doing reverse reads.
1 parent bb1712b commit f65fe34

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace {
2+
struct Foo {
3+
char string[10];
4+
};
5+
6+
void acquire(char*);
7+
8+
Foo* test_self_argument_flow() {
9+
Foo *info;
10+
acquire(info->string); // $ SPURIOUS: self-arg-flow
11+
12+
return info;
13+
}
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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_argument_flow.cpp" and
8+
source.asDefiningArgument() =
9+
any(Call call | call.getTarget().hasName("acquire")).getAnArgument()
10+
}
11+
12+
predicate isSink(DataFlow::Node sink) {
13+
sink.asIndirectArgument() = any(Call call | call.getTarget().hasName("acquire")).getAnArgument()
14+
}
15+
}
16+
17+
import DataFlow::Global<TestConfig>
18+
19+
module TestSelfArgumentFlow implements TestSig {
20+
string getARelevantTag() { result = "self-arg-flow" }
21+
22+
predicate hasActualResult(Location location, string element, string tag, string value) {
23+
exists(DataFlow::Node sink |
24+
flowTo(sink) and
25+
location = sink.getLocation() and
26+
element = sink.toString() and
27+
tag = "self-arg-flow" and
28+
value = ""
29+
)
30+
}
31+
}
32+
33+
import MakeTest<TestSelfArgumentFlow>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
| ref.cpp:120:17:120:18 | x3 | ref.cpp:129:10:129:11 | x3 |
1515
| ref.cpp:120:21:120:22 | x4 | ref.cpp:131:15:131:16 | x4 |
1616
| ref.cpp:120:21:120:22 | x4 | ref.cpp:132:10:132:11 | x4 |
17+
| self_argument_flow.cpp:9:10:9:13 | info | self_argument_flow.cpp:10:13:10:16 | info |
18+
| self_argument_flow.cpp:9:10:9:13 | info | self_argument_flow.cpp:12:12:12:15 | info |
1719
| test.cpp:75:7:75:8 | u1 | test.cpp:76:8:76:9 | u1 |
1820
| test.cpp:83:7:83:8 | u2 | test.cpp:84:13:84:14 | u2 |
1921
| test.cpp:83:7:83:8 | u2 | test.cpp:85:8:85:9 | u2 |

0 commit comments

Comments
 (0)