Skip to content

Commit 44239cb

Browse files
committed
Rust: Add taint tests for arrays
1 parent 27de43f commit 44239cb

File tree

1 file changed

+33
-0
lines changed
  • rust/ql/test/library-tests/dataflow/taint

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,44 @@ mod string {
4040
}
4141
}
4242

43+
mod array_source {
44+
fn source(i: i64) -> [i64; 3] {
45+
[i; 3]
46+
}
47+
48+
fn sink(i: i64) {
49+
println!("{}", i);
50+
}
51+
52+
pub fn array_tainted() {
53+
let arr = source(76);
54+
sink(arr[1]); // $ MISSING: hasTaintFlow=76
55+
}
56+
}
57+
58+
mod array_sink {
59+
fn source(i: i64) -> i64 {
60+
i
61+
}
62+
63+
fn sink(s: [i64; 3]) {
64+
println!("{}", s[1]);
65+
}
66+
67+
pub fn array_with_taint() {
68+
let mut arr2 = [1, 2, 3];
69+
arr2[1] = source(36);
70+
sink(arr2); // $ MISSING: hasTaintFlow=36
71+
}
72+
}
73+
4374
use string::*;
4475

4576
fn main() {
4677
addition();
4778
negation();
4879
cast();
4980
string_slice();
81+
array_source::array_tainted();
82+
array_sink::array_with_taint();
5083
}

0 commit comments

Comments
 (0)