Skip to content

value_oid_as is unsound #33

Open
Open
@Nugine

Description

@Nugine

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) };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions