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

Can't zero-initialize SockType #1212

Closed
srikwit opened this issue Apr 12, 2020 · 4 comments · Fixed by #1214
Closed

Can't zero-initialize SockType #1212

srikwit opened this issue Apr 12, 2020 · 4 comments · Fixed by #1214
Assignees

Comments

@srikwit
Copy link

srikwit commented Apr 12, 2020

Hi Team,

I have observed the following two tests to fail on my machine:

test sys::socket::sockopt::test::is_socket_type_dgram ... FAILED
test sys::socket::sockopt::test::is_socket_type_unix ... FAILED

Please let me know how I can help troubleshoot them.

@asomers
Copy link
Member

asomers commented Apr 12, 2020

Please tell us your operating system, kernel version, and Rust toolchain version. And paste the complete error message.

@srikwit
Copy link
Author

srikwit commented Apr 12, 2020

OS: Debian GNU/Linux 10 (buster)
Kernel version: 4.19.0-8-amd64
Rust toolchain: rustc 1.44.0-nightly (f509b26a7 2020-03-18)

Error message from cargo test:

failures:

---- sys::socket::sockopt::test::is_socket_type_dgram stdout ----
thread 'sys::socket::sockopt::test::is_socket_type_dgram' panicked at 'attempted to zero-initialize type `sys::socket::SockType`, which is invalid', /rustc/f509b26a7730d721ef87423a72b3fdf8724b4afa/src/libcore/mem/mod.rs:500:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- sys::socket::sockopt::test::is_socket_type_unix stdout ----
thread 'sys::socket::sockopt::test::is_socket_type_unix' panicked at 'attempted to zero-initialize type `sys::socket::SockType`, which is invalid', /rustc/f509b26a7730d721ef87423a72b3fdf8724b4afa/src/libcore/mem/mod.rs:500:5


failures:
    sys::socket::sockopt::test::is_socket_type_dgram
    sys::socket::sockopt::test::is_socket_type_unix

test result: FAILED. 41 passed; 2 failed; 2 ignored; 0 measured; 0 filtered out

@asomers
Copy link
Member

asomers commented Apr 12, 2020

This is a new error introduced by the latest nightly compiler. It really should just be a warning so as not to break existing code. But I'm already working on a fix.

@asomers asomers self-assigned this Apr 12, 2020
@asomers asomers changed the title Failed test Can't zero-initialize SockType Apr 12, 2020
@asomers
Copy link
Member

asomers commented Apr 12, 2020

Also, if this remains an error by the time that 1.44.0 goes stable, then we'll need to backport the fix to all currently used Nix releases.

bors bot added a commit that referenced this issue Apr 13, 2020
1214: Fix UB in getsockopt r=asomers a=asomers

The old code tried to zero-initialize an enum for which 0 is not a valid
value.  That worked for older compilers, but triggers a panic with Rust
1.44.0.  The correct technique is to use mem::MaybeUninit.

Fixes #1212

Co-authored-by: Alan Somers <asomers@gmail.com>
@bors bors bot closed this as completed in 35be3af Apr 13, 2020
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