Skip to content

Register trait is unsound #28

@WaffleLapkin

Description

@WaffleLapkin

Register trait allows reading and writing any pointer in safe code which is unsound.

Example:

use ruduino::Register;

struct Unsound;

impl Register for Unsound {
    type T = u8;

    const ADDRESS: *mut Self::T = core::ptr::null_mut();

    // default implementations of `write`, `read`, `set_musk_raw`, `toggle_raw`, 
    // `is_mask_set_raw` and `is_clear_raw` dereference `Self::ADDRESS`
    // (other methods also depend on them)
}

fn main() {
    println!("{}", Unsound::read());
}

(for me in debug it produces Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) and in the release mode it prints 0)

Possible solutions:

  • make Register trait unsafe
  • do not provide unsound default impls

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions