Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

value_oid_as is unsound #33

Open
Nugine opened this issue Jul 14, 2021 · 1 comment
Open

value_oid_as is unsound #33

Nugine opened this issue Jul 14, 2021 · 1 comment

Comments

@Nugine
Copy link

Nugine commented Jul 14, 2021

Transmuting bytes to an arbitrary type can cause undefined behavior.

The safety requirements:

  1. T must be Sized.
  2. The length of bytes must be equal to size_of::<T>().
  3. The alignment of bytes must be equal to align_of::<T>().
  4. T must be valid for any binary representation.

sysctl-rs/src/unix/funcs.rs

Lines 367 to 369 in 57c05e1

let val_array: Box<[u8]> = val.into_boxed_slice();
let val_raw: *mut T = Box::into_raw(val_array) as *mut T;
let val_box: Box<T> = unsafe { Box::from_raw(val_raw) };

@bigdogs
Copy link

bigdogs commented Apr 12, 2022

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants