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

Correctly read from a possibly misaligned pointer #615

Merged
merged 1 commit into from
Nov 28, 2019

Conversation

marmistrz
Copy link
Contributor

@marmistrz marmistrz commented Nov 21, 2019

This was reported in #513. read_unaligned is definitely the most ergonomic solution but clippy still marks this as an error, see rust-lang/rust-clippy#2881 for more details.

I also fixed a potentially misaligned write in the implementation of fd_readdir.

I can't ask for reviewers, so cc @kubkon @sunfishcode @peterhuene

Copy link
Member

@kubkon kubkon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not an expert but this looks great to me. While we’re here, would you mind checking that within wasi-common that’s all potential cases of misaligned pointers handled?

@marmistrz
Copy link
Contributor Author

I think these were the only places reported by clippy, but I'll recheck.

@kubkon
Copy link
Member

kubkon commented Nov 26, 2019

I think these were the only places reported by clippy, but I'll recheck.

Awesome, thanks a bunch! :-)

Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting this would be solved by aligning the buffer, since we're in control of that, however it appears Rust doesn't have nice ways to do that. But write_unaligned works too.

@sunfishcode sunfishcode merged commit b69758f into bytecodealliance:master Nov 28, 2019
@kubkon kubkon mentioned this pull request Dec 11, 2019
sunfishcode added a commit that referenced this pull request Dec 13, 2019
This reapplies #615, which was inadvertently reverted.
sunfishcode added a commit that referenced this pull request Dec 16, 2019
This reapplies #615, which was inadvertently reverted.
sunfishcode added a commit that referenced this pull request Dec 16, 2019
* Correctly handle possibly misaligned pointers in readdir

This reapplies #615, which was inadvertently reverted.

* Tidy up unneeded `self::` qualifiers.

* Make Dir's contents private.

Also remove the `unsafe` from `impl_iter`. With `Dir`'s field being
private, we can rely on the pointer being only what we've assigned to
it.

* Make `poll`'s timeout argument a `libc::c_int`.

This clarifies that there are no subsequent conversions before calling the
underlying libc API.

* Use clock_gettime instead of clock_getres to get the time.

* Mark FileType::from_raw as safe.

It handles unknown values, so it can be marked safe.
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

Successfully merging this pull request may close these issues.

3 participants