forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.rs
More file actions
95 lines (81 loc) · 2.13 KB
/
main.rs
File metadata and controls
95 lines (81 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn source(i: i64) -> i64 {
1000 + i
}
fn sink(s: i64) {
println!("{}", s);
}
// Flow through `clone` methods
fn option_clone() {
let a = Some(source(88));
sink(a.unwrap()); // $ hasValueFlow=88
let b = a.clone();
sink(b.unwrap()); // $ hasValueFlow=88
}
fn result_clone() {
let a: Result<i64, i64> = Ok(source(37));
sink(a.unwrap()); // $ hasValueFlow=37
let b = a.clone();
sink(b.unwrap()); // $ hasValueFlow=37
}
fn i64_clone() {
let a = source(12);
sink(a); // $ hasValueFlow=12
let b = a.clone();
sink(b); // $ MISSING: hasValueFlow=12 - lack of builtins means that we cannot resolve clone call above, and hence not insert implicit borrow
}
mod my_clone {
use super::{sink, source};
#[derive(Clone)]
struct Wrapper {
n: i64,
}
pub fn wrapper_clone() {
let w = Wrapper { n: source(73) };
match w {
Wrapper { n: n } => sink(n), // $ hasValueFlow=73
}
let u = w.clone();
match u {
Wrapper { n: n } => sink(n), // $ MISSING: hasValueFlow=73 - lack of expanded derives means that we cannot resolve clone call above, and hence not insert implicit borrow
}
}
}
mod flow_through_option {
use super::{sink, source};
// Test the auto generated flow summaries for `Option`
fn zip_flow() {
let a = Some(2);
let b = Some(source(38));
let z = a.zip(b);
match z {
Some((n, m)) => {
sink(n);
sink(m); // $ hasValueFlow=38
}
None => (),
}
}
fn higher_order_flow() {
let a = Some(0);
let b = a.map_or(3, |n| n + source(63));
sink(b); // $ hasTaintFlow=63
}
}
mod ptr {
use super::{sink, source};
fn read_write() {
let mut x: i64 = 0;
let y = &mut x as *mut i64;
unsafe {
sink(std::ptr::read(y));
std::ptr::write(y, source(30));
sink(std::ptr::read(y)); // $ hasValueFlow=30
}
}
}
fn main() {
option_clone();
result_clone();
i64_clone();
my_clone::wrapper_clone();
}