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

Undefined behaviour in winmm backend #137

Open
barafael opened this issue Jun 20, 2023 · 3 comments
Open

Undefined behaviour in winmm backend #137

barafael opened this issue Jun 20, 2023 · 3 comments

Comments

@barafael
Copy link
Contributor

barafael commented Jun 20, 2023

Here, a packet is filled by bytes from a message:

let packet: u32 = 0;
let ptr = &packet as *const u32 as *mut u8;
for i in 0..nbytes {
unsafe { *ptr.offset(i as isize) = message[i] };
}

This is undefined behaviour, because the address of an immutable u32 is taken and cast to a *mut u8, which is then written to in an unsafe block.

I have fixes ready in #136 but these are part of a rather large patchset, so if you like I can send a small patch ahead, too.

@barafael
Copy link
Contributor Author

barafael commented Jun 20, 2023

Here's a playground which you can use with Miri to see that it's actually undefined behaviour: playground link

@Boddlnagg
Copy link
Owner

Sorry, I have somehow missed this PR! I will probably just merge #136 eventually (after #135 and a rebase), I don't think a separate PR is necessary.

@barafael
Copy link
Contributor Author

OK. I just did this PR because I wasn't sure you wanted to have the large blob of changes in #136 .

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