Skip to content

Commit cd2038a

Browse files
committed
Rust: Setup inline flow test library
1 parent d6ef8c3 commit cd2038a

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
models
2+
edges
3+
nodes
4+
subpaths
5+
testFailures
6+
| main.rs:17:22:17:40 | Comment | Missing result: hasValueFlow=1 |
7+
| main.rs:22:14:22:32 | Comment | Missing result: hasValueFlow=1 |
8+
| main.rs:33:14:33:32 | Comment | Missing result: hasValueFlow=1 |
9+
#select
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import rust
6+
import utils.InlineFlowTest
7+
import DefaultFlowTest
8+
import ValueFlow::PathGraph
9+
10+
from ValueFlow::PathNode source, ValueFlow::PathNode sink
11+
where ValueFlow::flowPath(source, sink)
12+
select sink, source, sink, "$@", source, source.toString()
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fn source() -> &'static str {
1+
fn source(i: i64) -> &'static str {
22
"source"
33
}
44

@@ -13,18 +13,22 @@ fn sanitize(s: &str) -> &str {
1313
}
1414
}
1515

16-
fn no_barrier() {
17-
let s = source();
18-
sink(s);
16+
fn directly() {
17+
sink(source(1)); // $ hasValueFlow=1
18+
}
19+
20+
fn through_variable() {
21+
let s = source(1);
22+
sink(s); // $ hasValueFlow=1
1923
}
2024

2125
fn with_barrier() {
22-
let s = source();
26+
let s = source(1);
2327
let s = sanitize(s);
2428
sink(s);
2529
}
2630

2731
fn main() {
28-
let s = source();
29-
sink(s);
32+
let s = source(1);
33+
sink(s); // $ hasValueFlow=1
3034
}

rust/ql/test/utils/InlineFlowTest.qll

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Inline flow tests for Rust.
3+
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
4+
*/
5+
6+
import rust
7+
private import codeql.dataflow.test.InlineFlowTest
8+
private import codeql.rust.dataflow.DataFlow
9+
private import codeql.rust.dataflow.internal.DataFlowImpl
10+
private import codeql.rust.dataflow.internal.TaintTrackingImpl
11+
private import internal.InlineExpectationsTestImpl as InlineExpectationsTestImpl
12+
13+
private module FlowTestImpl implements InputSig<Location, RustDataFlow> {
14+
predicate defaultSource(DataFlow::Node source) {
15+
source.asExpr().(CallExpr).getExpr().toString() = "source"
16+
}
17+
18+
predicate defaultSink(DataFlow::Node sink) {
19+
any(CallExpr call | call = sink.asExpr() and call.getExpr().toString() = "sink")
20+
.getArgList()
21+
.getAnArg() = sink.asExpr()
22+
}
23+
24+
private string getSourceArgString(DataFlow::Node src) {
25+
defaultSource(src) and
26+
result = src.asExpr().(CallExpr).getArgList().getArg(0).toString()
27+
}
28+
29+
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
30+
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
31+
exists(sink)
32+
}
33+
34+
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { none() }
35+
}
36+
37+
import InlineFlowTestMake<Location, RustDataFlow, RustTaintTracking, InlineExpectationsTestImpl::Impl, FlowTestImpl>

0 commit comments

Comments
 (0)