-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path0157-id-map.rs
82 lines (67 loc) · 1.76 KB
/
0157-id-map.rs
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
/*!
```rudra-poc
[target]
crate = "id-map"
version = "0.2.1"
[[target.peer]]
crate = "id-set"
version = "0.2.1"
[report]
issue_url = "https://github.com/andrewhickman/id-map/issues/3"
issue_date = 2021-02-26
rustsec_url = "https://github.com/RustSec/advisory-db/pull/863"
rustsec_id = "RUSTSEC-2021-0052"
[[bugs]]
analyzer = "UnsafeDataflow"
bug_class = "PanicSafety"
bug_count = 3
rudra_report_locations = [
"src/lib.rs:369:5: 381:6",
"src/lib.rs:167:5: 184:6",
"src/lib.rs:188:5: 207:6",
]
```
!*/
#![forbid(unsafe_code)]
use id_map::IdMap;
use id_set::IdSet;
struct DropDetector(u32);
impl Drop for DropDetector {
fn drop(&mut self) {
println!("Dropping {}", self.0);
}
}
impl Clone for DropDetector {
fn clone(&self) -> Self { panic!("Panic on clone!"); }
}
fn main() {
//clone_from_panic_will_drop_invalid_memory();
//get_or_insert_with_leaves_state_inconsistent();
remove_set_leaves_state_inconsistent_if_drop_panics();
}
fn clone_from_panic_will_drop_invalid_memory() {
let mut map = IdMap::new();
map.insert(DropDetector(1));
let mut map_2 = IdMap::new();
map_2.insert(DropDetector(2));
map_2.clone_from(&map);
}
fn get_or_insert_with_leaves_state_inconsistent() {
let mut map : IdMap<DropDetector> = IdMap::with_capacity(0);
map.get_or_insert_with(0, || panic!("Panic in insertion function!"));
}
struct PanicsOnDrop(u32, bool);
impl Drop for PanicsOnDrop {
fn drop(&mut self) {
println!("Dropping {}", self.0);
if (self.1) {
self.1 = false;
panic!("Panicking on drop");
}
}
}
fn remove_set_leaves_state_inconsistent_if_drop_panics() {
let mut map = IdMap::new();
map.insert(PanicsOnDrop(1, true));
map.remove_set(&IdSet::new_filled(1));
}