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

Register trait is unsound #28

Open
WaffleLapkin opened this issue Jul 26, 2020 · 1 comment
Open

Register trait is unsound #28

WaffleLapkin opened this issue Jul 26, 2020 · 1 comment

Comments

@WaffleLapkin
Copy link

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
@shepmaster
Copy link
Member

Yeah that should definitely be an unsafe trait. Maybe also sealed as no one should be able to implement it out of the library.

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