-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path0073-stderr.rs
49 lines (40 loc) · 1.12 KB
/
0073-stderr.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
/*!
```rudra-poc
[target]
crate = "stderr"
version = "0.8.0"
[report]
issue_url = "https://github.com/biluohc/stderr/issues/5"
issue_date = 2020-12-22
rustsec_url = "https://github.com/RustSec/advisory-db/pull/585"
rustsec_id = "RUSTSEC-2020-0109"
[[bugs]]
analyzer = "SendSyncVariance"
bug_class = "SendSyncVariance"
rudra_report_locations = ["src/static_mut.rs:62:1: 62:40"]
[[bugs]]
analyzer = "Manual"
guide = "SendSyncVariance"
bug_class = "Other"
rudra_report_locations = []
```
!*/
#![forbid(unsafe_code)]
use stderr::StaticMut;
// A simple tagged union used to demonstrate problems with aliasing.
#[derive(Debug, Clone, Copy)]
enum RefOrInt {
Ref(&'static u64),
Int(u128),
}
fn main() {
let ptr = StaticMut::new(RefOrInt::Ref(&42));
let mutable_ref_one = ptr.as_mut();
let mutable_ref_two = ptr.as_mut();
println!("Pointer points to: {:?}", mutable_ref_one);
if let RefOrInt::Ref(ref addr) = mutable_ref_one {
*mutable_ref_two = RefOrInt::Int(0xdeadbeef);
println!("Pointer now points to: {:p}", *addr);
println!("Dereferencing addr will now segfault: {}", **addr);
}
}