Rust: Setup inline flow test library

This commit is contained in:
Simon Friis Vindum
2024-11-11 16:41:59 +01:00
parent d6ef8c3f9a
commit cd2038a8f8
4 changed files with 69 additions and 7 deletions

View File

@@ -0,0 +1,9 @@
models
edges
nodes
subpaths
testFailures
| main.rs:17:22:17:40 | Comment | Missing result: hasValueFlow=1 |
| main.rs:22:14:22:32 | Comment | Missing result: hasValueFlow=1 |
| main.rs:33:14:33:32 | Comment | Missing result: hasValueFlow=1 |
#select

View File

@@ -0,0 +1,12 @@
/**
* @kind path-problem
*/
import rust
import utils.InlineFlowTest
import DefaultFlowTest
import ValueFlow::PathGraph
from ValueFlow::PathNode source, ValueFlow::PathNode sink
where ValueFlow::flowPath(source, sink)
select sink, source, sink, "$@", source, source.toString()

View File

@@ -1,4 +1,4 @@
fn source() -> &'static str {
fn source(i: i64) -> &'static str {
"source"
}
@@ -13,18 +13,22 @@ fn sanitize(s: &str) -> &str {
}
}
fn no_barrier() {
let s = source();
sink(s);
fn directly() {
sink(source(1)); // $ hasValueFlow=1
}
fn through_variable() {
let s = source(1);
sink(s); // $ hasValueFlow=1
}
fn with_barrier() {
let s = source();
let s = source(1);
let s = sanitize(s);
sink(s);
}
fn main() {
let s = source();
sink(s);
let s = source(1);
sink(s); // $ hasValueFlow=1
}

View File

@@ -0,0 +1,37 @@
/**
* Inline flow tests for Rust.
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
*/
import rust
private import codeql.dataflow.test.InlineFlowTest
private import codeql.rust.dataflow.DataFlow
private import codeql.rust.dataflow.internal.DataFlowImpl
private import codeql.rust.dataflow.internal.TaintTrackingImpl
private import internal.InlineExpectationsTestImpl as InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<Location, RustDataFlow> {
predicate defaultSource(DataFlow::Node source) {
source.asExpr().(CallExpr).getExpr().toString() = "source"
}
predicate defaultSink(DataFlow::Node sink) {
any(CallExpr call | call = sink.asExpr() and call.getExpr().toString() = "sink")
.getArgList()
.getAnArg() = sink.asExpr()
}
private string getSourceArgString(DataFlow::Node src) {
defaultSource(src) and
result = src.asExpr().(CallExpr).getArgList().getArg(0).toString()
}
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
exists(sink)
}
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { none() }
}
import InlineFlowTestMake<Location, RustDataFlow, RustTaintTracking, InlineExpectationsTestImpl::Impl, FlowTestImpl>