-
Notifications
You must be signed in to change notification settings - Fork 683
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 UB in the SO_TYPE sockopt #1821
Conversation
@@ -121,6 +121,24 @@ pub enum SockType { | |||
#[cfg(not(any(target_os = "haiku")))] | |||
Rdm = libc::SOCK_RDM, | |||
} | |||
// The TryFrom impl could've been derived using libc_enum!. But for | |||
// backwards-compatibility with Nix-0.25.0 we manually implement it, so as to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asomers I'm interpreting this as driving a patch, is that the intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean so we can build patch releases? Yes, I think that's worthwhile. But even for new releases too I think it's annoying to force people to change SockType::Stream to SockType::SOCK_STREAM without great reason.
I fixed the formatting. And rather than figure out how to determine whether a Fuchsia process can create raw sockets, I'm just skipping that test on Fuchsia. |
@ahcodedthat does this patch solve your original problem? |
Yes, that works. The example program now just fails cleanly with I suggest mentioning in the documentation for It might also be wise to use a different error code, since the |
When reading a value into an enum from getsockopt, we must validate it. Failing to do so can lead to UB for example with SOCK_PACKET on Linux. Perform the validation in GetSockOpt::get. Currently SockType is the only type that requires validation. Fixes nix-rust#1819
@rtzoeller I stupidly forgot about this PR when I made the 0.26.0 release a few minutes ago. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes it's important to stress test cargo release
by releasing multiple times in quick succession. Glad you caught it now.
bors r+ |
When reading a value into an enum from getsockopt, we must validate it. Failing to do so can lead to UB for example with SOCK_PACKET on Linux.
Perform the validation in GetSockOpt::get. Currently SockType is the only type that requires validation.
Fixes #1819