-
Notifications
You must be signed in to change notification settings - Fork 5
/
0077-va-ts.rs
54 lines (48 loc) · 1.55 KB
/
0077-va-ts.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
/*!
```rudra-poc
[target]
crate = "va-ts"
version = "0.0.3"
[report]
issue_url = "https://github.com/video-audio/va-ts/issues/4"
issue_date = 2020-12-22
rustsec_url = "https://github.com/RustSec/advisory-db/pull/642"
rustsec_id = "RUSTSEC-2020-0114"
[[bugs]]
analyzer = "SendSyncVariance"
bug_class = "SendSyncVariance"
rudra_report_locations = ["src/demuxer.rs:265:1: 265:61"]
```
!*/
#![forbid(unsafe_code)]
use std::ops::Drop;
use std::sync::{Mutex, MutexGuard};
use std::thread::{self, ThreadId};
use va_ts::{DemuxedPacket, DemuxedTable, Demuxer, DemuxerEvents, SubtableID};
struct X(MutexGuard<'static, u64>, ThreadId);
impl DemuxerEvents for X {
fn on_table(&mut self, _: SubtableID, _: &DemuxedTable) {}
fn on_packet(&mut self, _: &DemuxedPacket) {}
}
impl Drop for X {
fn drop(&mut self) {
// `MutexGuard` must not be dropped from a thread that didn't lock the `Mutex`.
//
// If a thread attempts to unlock a Mutex that it has not locked, it can result in undefined behavior.
// (https://github.com/rust-lang/rust/issues/23465#issuecomment-82730326)
assert_eq!(self.1, thread::current().id());
}
}
fn main() {
let static_mutex = Box::leak(Box::new(Mutex::new(0xbeefbeef_u64)));
// MutexGuard is `!Send`
let mutex_guard = static_mutex.lock().unwrap();
let tid = thread::current().id();
let demuxer = Demuxer::new(X(mutex_guard, tid));
std::thread::spawn(move || {
let demuxer = demuxer;
// demuxer is dropped here, along with `MutexGuard`.
})
.join()
.unwrap();
}