-
Notifications
You must be signed in to change notification settings - Fork 4
/
0111-insert_many.rs
62 lines (47 loc) · 1.29 KB
/
0111-insert_many.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
/*!
```rudra-poc
[target]
crate = "insert_many"
version = "0.1.1"
[report]
issue_url = "https://github.com/rphmeier/insert_many/issues/1"
issue_date = 2021-01-26
rustsec_url = "https://github.com/RustSec/advisory-db/pull/832"
rustsec_id = "RUSTSEC-2021-0042"
[[bugs]]
analyzer = "UnsafeDataflow"
bug_class = "PanicSafety"
bug_count = 2
rudra_report_locations = ["src/lib.rs:52:5: 54:6", "src/lib.rs:59:5: 61:6"]
```
!*/
#![forbid(unsafe_code)]
use insert_many::InsertMany;
struct DropDetector(u32);
impl Drop for DropDetector {
fn drop(&mut self) {
println!("Dropping {}", self.0);
}
}
// A type with an iterator that panics.
// -----
struct MyCollection();
impl IntoIterator for MyCollection {
type Item = DropDetector;
type IntoIter = PanickingIterator;
fn into_iter(self) -> Self::IntoIter { PanickingIterator() }
}
struct PanickingIterator();
impl Iterator for PanickingIterator {
type Item = DropDetector;
fn next(&mut self) -> Option<Self::Item> { panic!("Iterator panicked"); }
}
impl ExactSizeIterator for PanickingIterator {
fn len(&self) -> usize { 1 }
}
// -----
fn main() {
let mut v = vec![DropDetector(1), DropDetector(2)];
// Inserting many elements from a panicking iterator will cause a double-drop.
v.insert_many(0, MyCollection());
}