-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path0018-dync.rs
45 lines (37 loc) · 1.06 KB
/
0018-dync.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
/*!
```rudra-poc
[target]
crate = "dync"
version = "0.4.0"
[report]
issue_url = "https://github.com/elrnv/dync/issues/4"
issue_date = 2020-09-27
rustsec_url = "https://github.com/RustSec/advisory-db/pull/411"
rustsec_id = "RUSTSEC-2020-0050"
[[bugs]]
analyzer = "Manual"
guide = "UnsafeDestructor"
bug_class = "Other"
rudra_report_locations = []
```
!*/
#![forbid(unsafe_code)]
mod boilerplate;
use dync::{VTable, VecCopy};
#[repr(align(256))]
#[derive(Copy, Clone)]
struct LargeAlign(u8);
impl VTable<LargeAlign> for LargeAlign {
fn build_vtable() -> Self {
LargeAlign(0)
}
}
fn main() {
// The backing storage for a VecCopy is a u8, meaning that casting to a type
// with different alignment requires triggers undefined behavior.
// https://github.com/elrnv/dync/blob/c133056676582dd0e28c14526175d0c9ae01a905/src/vec_copy.rs#L64-L65
let mut x = VecCopy::<LargeAlign>::with_type();
x.push_as::<LargeAlign>(LargeAlign(0));
let ref_to_element = x.get_ref_as::<LargeAlign>(0).unwrap();
boilerplate::assert_aligned(ref_to_element);
}