Skip to content

Commit 70a296b

Browse files
committed
Rust: Add string slice taint flow test
1 parent 2ada999 commit 70a296b

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

rust/ql/test/library-tests/dataflow/taint/TaintFlowStep.expected

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import codeql.rust.dataflow.DataFlow
2+
import codeql.rust.dataflow.internal.TaintTrackingImpl
3+
4+
query predicate additionalTaintStep = RustTaintTracking::defaultAdditionalTaintStep/3;

rust/ql/test/library-tests/dataflow/taint/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,27 @@ fn cast() {
2424
sink(b as i64); // $ MISSING: hasTaintFlow=77
2525
}
2626

27+
mod string {
28+
fn source(i: i64) -> String {
29+
format!("{}", i)
30+
}
31+
32+
fn sink(s: &str) {
33+
println!("{}", s);
34+
}
35+
36+
pub fn string_slice() {
37+
let s = source(35);
38+
let sliced = &s[1..3];
39+
sink(sliced); // $ MISSING: hasTaintFlow=35
40+
}
41+
}
42+
43+
use string::*;
44+
2745
fn main() {
2846
addition();
2947
negation();
3048
cast();
49+
string_slice();
3150
}

0 commit comments

Comments
 (0)