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

Improve the UB situation in layout tests. #2064

Closed
wants to merge 2 commits into from
Closed

Conversation

emilio
Copy link
Contributor

@emilio emilio commented Jun 6, 2021

This is #2055 with some extra fixes

@highfive
Copy link

highfive commented Jun 6, 2021

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

russell-islam added a commit to russell-islam/cloud-hypervisor that referenced this pull request Jun 22, 2021
This patch addresses this issue rust-lang/rust-bindgen#2064.
While we access field of packed struct the compiler can generate the
correct code to create a temporary variable to access the packed struct
field. Access withing {} ensures that.

Signed-off-by: Muminul Islam <[email protected]>
russell-islam added a commit to russell-islam/cloud-hypervisor that referenced this pull request Jun 22, 2021
This patch addresses this issue rust-lang/rust-bindgen#2064.
While we access field of packed struct the compiler can generate the
correct code to create a temporary variable to access the packed struct
field. Access withing {} ensures that.

Signed-off-by: Muminul Islam <[email protected]>
likebreath pushed a commit to cloud-hypervisor/cloud-hypervisor that referenced this pull request Jun 22, 2021
This patch addresses this issue rust-lang/rust-bindgen#2064.
While we access field of packed struct the compiler can generate the
correct code to create a temporary variable to access the packed struct
field. Access withing {} ensures that.

Signed-off-by: Muminul Islam <[email protected]>
@jyn514
Copy link
Member

jyn514 commented Nov 17, 2021

Hi @emilio, is there anything blocking you from merging this? It would be super helpful for all the projects using bindgen :)

@emilio
Copy link
Contributor Author

emilio commented Nov 26, 2021

Yeah, some tests are failing, I don't recall the specifics, need to look into that, will re-push.

Apostoln and others added 2 commits November 26, 2021 02:44
 - Replaced dereferencing of null ptr with
   zero bit pattern + transmute + std::ptr::addr_of!
   to avoid UB. It affects only checks of fields offsets
 - Overwritten expected with BINDGEN_OVERWRITE_EXPECTED=1
 - Overwritten test_multiple_header_calls_in_builder and test_mixed_header_and_header_contents
   manually because #2054
 - Do not check the layout for repr(C) unions
 - Do not call the destructor of tmp struct to avoid other UB
@elichai
Copy link
Contributor

elichai commented Nov 26, 2021

Out of curiosity, why zero memory and not a MaybeUninit?
This means that in the future you can't add support for things like str / refrences / boxes / NonNull etc. (anything that has a niche or validity rules)

(Using MaybeUninit like that is explicitly defined here: https://doc.rust-lang.org/beta/std/mem/union.MaybeUninit.html#initializing-a-struct-field-by-field)

@bors-servo
Copy link

☔ The latest upstream changes (presumably 310f7f8) made this pull request unmergeable. Please resolve the merge conflicts.

@kulp kulp mentioned this pull request Jun 1, 2022
@kulp
Copy link
Member

kulp commented Jun 1, 2022

It appears that this (like #2055) has a little more in it than #2203 did, but since #1651 is now closed, I am inferring that this PR is no longer needed, so I am closing it.

If I missed something, let me know.

@kulp kulp closed this Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants