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

ptr -> usize transmute + read is UB #2

Open
saethlin opened this issue Mar 9, 2024 · 0 comments
Open

ptr -> usize transmute + read is UB #2

saethlin opened this issue Mar 9, 2024 · 0 comments

Comments

@saethlin
Copy link

saethlin commented Mar 9, 2024

Rust has Provenance so this transmute of an integer to a pointer then read through that pointer is UB, because integers cannot carry provenance:

context_bind/src/lib.rs

Lines 198 to 201 in 42c4fb2

let val: usize = mem::transmute(ptr);
let ptr0: *const ORG = mem::transmute(val.clone());
let ptr1: *mut ORG = mem::transmute(val.clone());
if let (Some(t),_) = read_ptr(ptr0) {

The usual fix is to not have an intermediate usize and use any pointer type instead. I'm not making a PR to fix this because the last commit to this repo was 8 years ago, but this did show up in a crater run: rust-lang/rust#121282

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