-
Notifications
You must be signed in to change notification settings - Fork 4
/
0125-multiqueue.rs
73 lines (63 loc) · 1.72 KB
/
0125-multiqueue.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
/*!
```rudra-poc
[target]
crate = "multiqueue"
version = "0.3.2"
[[target.peer]]
crate = "futures"
version = "0.1.27"
[report]
issue_url = "https://github.com/schets/multiqueue/issues/31"
issue_date = 2020-12-25
rustsec_url = "https://github.com/RustSec/advisory-db/pull/744"
rustsec_id = "RUSTSEC-2020-0143"
[[bugs]]
analyzer = "SendSyncVariance"
bug_class = "SendSyncVariance"
bug_count = 4
rudra_report_locations = [
"src/multiqueue.rs:1058:1: 1058:60",
"src/multiqueue.rs:1059:1: 1059:60",
"src/multiqueue.rs:1060:1: 1060:63",
"src/multiqueue.rs:1061:1: 1061:63",
]
```
!*/
#![forbid(unsafe_code)]
use std::cell::Cell;
use std::sync::Arc;
use std::thread;
// futures = "0.1.27"
use futures::{Future, Sink, Stream};
#[derive(Debug, Clone, Copy)]
enum RefOrInt<'a> {
Ref(&'a u64),
Int(u64),
}
static X: u64 = 0;
use multiqueue::mpmc_fut_queue;
fn main() {
let (tx, rx) = mpmc_fut_queue(16);
let cell = Arc::new(Cell::new(RefOrInt::Int(0xdeadbeef)));
let sent = tx.send(Arc::clone(&cell));
thread::spawn(move || {
let mut rx = rx.wait();
// parent thread sent us an object that is not `Send`!
let smuggled_cell = rx.next().unwrap().unwrap();
loop {
smuggled_cell.set(RefOrInt::Int(0xdeadbeef));
smuggled_cell.set(RefOrInt::Ref(&X))
}
});
sent.wait().unwrap();
loop {
if let RefOrInt::Ref(addr) = cell.get() {
if addr as *const _ as usize != 0xdeadbeef {
continue;
}
// Due to the data race, obtaining Ref(0xdeadbeef) is possible
println!("Pointer is now: {:p}", addr);
println!("Dereferencing addr will now segfault: {}", *addr);
}
}
}