mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Rust: Setup inline flow test library
This commit is contained in:
@@ -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
|
||||
12
rust/ql/test/library-tests/dataflow/barrier/inline-flow.ql
Normal file
12
rust/ql/test/library-tests/dataflow/barrier/inline-flow.ql
Normal 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()
|
||||
@@ -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
|
||||
}
|
||||
|
||||
37
rust/ql/test/utils/InlineFlowTest.qll
Normal file
37
rust/ql/test/utils/InlineFlowTest.qll
Normal 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>
|
||||
Reference in New Issue
Block a user