-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path0013-simple-slab.rs
50 lines (40 loc) · 1.08 KB
/
0013-simple-slab.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
/*!
```rudra-poc
[target]
crate = "simple-slab"
version = "0.3.2"
[report]
issue_url = "https://github.com/nathansizemore/simple-slab/issues/2"
issue_date = 2020-09-03
rustsec_url = "https://github.com/RustSec/advisory-db/pull/376"
rustsec_id = "RUSTSEC-2020-0039"
[[bugs]]
analyzer = "Manual"
guide = "UnsafeDestructor"
bug_class = "Other"
bug_count = 2
rudra_report_locations = []
```
!*/
#![forbid(unsafe_code)]
mod boilerplate;
use simple_slab::Slab;
#[derive(Debug, PartialEq)]
struct DropDetector(u32);
impl Drop for DropDetector {
fn drop(&mut self) {
println!("Dropping {}", self.0);
}
}
fn main() {
boilerplate::init();
let mut slab = Slab::with_capacity(2);
slab.insert(DropDetector(123));
slab.insert(DropDetector(456));
// 1. No boundary checking leads to OOB read in `index()`
println!("{:?}", slab[20]);
// 2. Memory leak / uninitialized memory access in `remove()`
// element should be copied from `len - 1`, not `len`
assert_eq!(slab.remove(0).0, 123);
assert_eq!(slab[0].0, 456); // copied from uninitialized region `slab[2]`
}