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

Potential footgun in ReadBuf being mem::replaced. #2827

Closed
seanmonstar opened this issue Sep 8, 2020 · 4 comments
Closed

Potential footgun in ReadBuf being mem::replaced. #2827

seanmonstar opened this issue Sep 8, 2020 · 4 comments
Assignees
Labels
A-tokio Area: The main tokio crate C-maintenance Category: PRs that clean code up or issues documenting cleanup. M-io Module: tokio/io
Milestone

Comments

@seanmonstar
Copy link
Member

In tokio 0.3, we've adopted the new ReadBuf API for AsyncRead. It's been noticed that there is a potential footgun if an implementor replaces the ReadBuf with a different buffer.

Original issue: rust-lang/rfcs#2930 (comment)

Example

let mut buf = ReadBuf::uninit(&mut some_uninit_buf);
io.poll_read(cx, &mut buf);
let len = buf.filled().len();
return &some_uninit_buf[..len]

One possible solution is to point out that a user should check buf.filled().as_ptr() is still the same.

@seanmonstar seanmonstar added A-tokio Area: The main tokio crate M-io Module: tokio/io labels Sep 8, 2020
@seanmonstar seanmonstar added this to the v0.3 milestone Sep 8, 2020
@Darksonn Darksonn added the C-maintenance Category: PRs that clean code up or issues documenting cleanup. label Sep 9, 2020
@carllerche
Copy link
Member

I do not believe that this is an 0.3 blocker.

@carllerche
Copy link
Member

@seanmonstar you have thoughts on how to proceed here? Will we need any breaking changes to handle this or can we add utility shims on top?

@seanmonstar
Copy link
Member Author

My thoughts aren't much deeper than "well don't do that". The proposed fix feels even grosser (providing some ReadBufHolder<'_> that holds a &mut ReadBuf and is passed by-value to prevent this). 🤷

@carllerche
Copy link
Member

Ok, it is a low-level API and involves unsafe. Let's punt on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-maintenance Category: PRs that clean code up or issues documenting cleanup. M-io Module: tokio/io
Projects
None yet
Development

No branches or pull requests

3 participants