Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7517ad3

Browse filesBrowse files
authored
Merge pull request #17959 from paldepind/rust-inline-flow-test
Rust: Setup inline flow test library
2 parents 77ae26f + d9d3027 commit 7517ad3
Copy full SHA for 7517ad3

File tree

Expand file treeCollapse file tree

4 files changed

+74
-7
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+74
-7
lines changed
+9Lines 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
+12Lines 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()
+11-7Lines 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

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
bindingset[src, sink]
30+
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
31+
(
32+
result = getSourceArgString(src)
33+
or
34+
not exists(getSourceArgString(src)) and result = ""
35+
) and
36+
exists(sink)
37+
}
38+
39+
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { none() }
40+
}
41+
42+
import InlineFlowTestMake<Location, RustDataFlow, RustTaintTracking, InlineExpectationsTestImpl::Impl, FlowTestImpl>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.