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

Unsoundness in <SockRef as From<&AsRawFd>>::from #229

Closed
coolreader18 opened this issue May 3, 2021 · 5 comments · Fixed by #253
Closed

Unsoundness in <SockRef as From<&AsRawFd>>::from #229

coolreader18 opened this issue May 3, 2021 · 5 comments · Fixed by #253

Comments

@coolreader18
Copy link
Contributor

You can do something like:

let sock = socket2::SockRef::from(&-1);
assert!(Some(sock).is_none());

With the changes in #222

@Thomasdezeeuw
Copy link
Collaborator

This is the same problem as being discussed in #229, SockRef::from needs to ensure the RawFd is valid, but currently doesn't.

@Thomasdezeeuw
Copy link
Collaborator

Whoops I meant #218.

@coolreader18
Copy link
Contributor Author

coolreader18 commented May 3, 2021

Ah, sorry about that, shoulda checked.

@coolreader18
Copy link
Contributor Author

coolreader18 commented May 3, 2021

Oh, wait, I'll add this to that discussion, but this is actually unsound language-wise, not just questionably unsafe/non-private - because of the niche optimization from #222, you can create an invalid value in safe code.

@Thomasdezeeuw
Copy link
Collaborator

Oh, wait, I'll add this to that discussion, but this is actually unsound language-wise, not just questionably unsafe/non-private - because of the niche optimization from #222, you can create an invalid value in safe code.

You're right using -1 is even worse, but as #222 is talking about a redesign I though it best to not have two concurrent threads talking about the same thing. But this is definitely blocking a v0.4.1 release (which would include #222).

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 a pull request may close this issue.

2 participants