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

Fix fd_readdir to properly truncate directory entry names. #2620

Merged
merged 2 commits into from
Feb 1, 2021

Conversation

peterhuene
Copy link
Member

Previously, fd_readdir was truncating directory entry names based on the
calculation of min(name_len, buf_len - bufused), but bufused was not being
updated after writing in the dirent structure to the buffer.

This allowed bufused to be incremented beyond buf_len and returned as the
number of bytes written to the buffer, which is invalid.

This fix adjusts bufused when the buffer is written to for the dirent so
that name truncation happens as expected.

Fixes #2618.

@peterhuene peterhuene added the wasi:impl Issues pertaining to WASI implementation in Wasmtime label Jan 28, 2021
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Jan 28, 2021
@github-actions
Copy link

Subscribe to Label Action

cc @kubkon

This issue or pull request has been labeled: "wasi", "wasi:impl"

Thus the following users have been cc'd because of the following labels:

  • kubkon: wasi

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

peterhuene added a commit to peterhuene/wasmtime that referenced this pull request Jan 28, 2021
This commit removes what appears to be a workaround to the bug being fixed by
the change in bytecodealliance#2620.
peterhuene added a commit to peterhuene/wasmtime that referenced this pull request Jan 28, 2021
This commit removes what appears to be a workaround to the bug being fixed by
the change in bytecodealliance#2620.
Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

This code is very confusing and I very much look forwards to re-designing this interface in a future WASI so that none of this nonsense is required. Thank you for the fix!

pchickey added a commit that referenced this pull request Feb 1, 2021
Previously, `fd_readdir` was truncating directory entry names based on the
calculation of `min(name_len, buf_len - bufused)`, but `bufused` was not being
updated after writing in the `dirent` structure to the buffer.

This allowed `bufused` to be incremented beyond `buf_len` and returned as the
number of bytes written to the buffer, which is invalid.

This fix adjusts `bufused` when the buffer is written to for the `dirent` so
that name truncation happens as expected.

Fixes bytecodealliance#2618.
This commit removes what appears to be a workaround to the bug being fixed by
the change in bytecodealliance#2620.
@peterhuene peterhuene merged commit 256cc8a into bytecodealliance:main Feb 1, 2021
@peterhuene peterhuene deleted the fix-fd-readdir branch February 1, 2021 20:30
peterhuene added a commit to peterhuene/wasmtime that referenced this pull request Feb 4, 2021
This commit removes what appears to be a workaround to the bug being fixed by
the change in bytecodealliance#2620.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi:impl Issues pertaining to WASI implementation in Wasmtime wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Readdir doesn't correctly handle capacity updates
2 participants