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

Mark memset function as unsafe #331

Open
kitcatier opened this issue Mar 17, 2023 · 0 comments
Open

Mark memset function as unsafe #331

kitcatier opened this issue Mar 17, 2023 · 0 comments

Comments

@kitcatier
Copy link

Hello, I found a soundness issue in this crate.

ckb-vm/src/memory/mod.rs

Lines 131 to 138 in 1642d8f

// Keep this in a central place to allow for future optimization
#[inline(always)]
pub fn memset(slice: &mut [u8], value: u8) {
let p = slice.as_mut_ptr();
unsafe {
ptr::write_bytes(p, value, slice.len());
}
}

The unsafe function called needs to ensure that the parameter must be:

  • dst must be valid for writes of count * size_of::() bytes.
  • dst must be properly aligned.
    https://doc.rust-lang.org/std/ptr/fn.write_bytes.html
    and the developer who calls the ref_as_nonnull function may not notice this safety requirement.
    Marking them unsafe also means that callers must make sure they know what they're doing.
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

1 participant