Open
Description
I tried this code, compiling in debug mode with -C target-feature=+crt-static
enabled:
use std::net::ToSocketAddrs;
fn main() {
drop(("127.0.0.1 localhost", 80u16).to_socket_addrs());
println!("Success");
}
I expected to see this happen: the program exits and prints Success
.
Instead, this happened: When running the program on Oracle Linux 9, the program crashes (killed with signal 11/SEGV) with a segmentation fault, indicating undefined behavior. The program only crashes when statically linking the C runtime.
Meta
rustc --version --verbose
:
rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: x86_64-unknown-linux-gnu
release: 1.72.0
LLVM version: 16.0.5
Backtrace
I collected the backtrace using GDB.
#0 0x00007f712d0cd4d4 in __nss_readline () from /lib64/libc.so.6
#1 0x00007f712d0d06ee in internal_getent () from /lib64/libc.so.6
#2 0x00007f712d0d17a9 in _nss_files_gethostbyname4_r () from /lib64/libc.so.6
#3 0x00007f712d20fadf in gaih_inet.constprop ()
#4 0x00007f712d211629 in getaddrinfo ()
#5 0x00007f712d19ae61 in std::sys_common::net::{impl#6}::try_from::{closure#0} () at library/std/src/sys_common/net.rs:206
#6 0x00007f712d195216 in std::sys::common::small_c_string::run_with_cstr<std::sys_common::net::LookupHost, std::sys_common::net::{impl#6}::try_from::{closure_env#0}> () at library/std/src/sys/common/small_c_string.rs:43
#7 std::sys_common::net::{impl#6}::try_from () at library/std/src/sys_common/net.rs:201
#8 core::convert::{impl#6}::try_into<(&str, u16), std::sys_common::net::LookupHost> () at library/core/src/convert/mod.rs:755
#9 std::net::socket_addr::{impl#10}::to_socket_addrs () at library/std/src/net/socket_addr.rs:266
#10 0x00007f712d17a756 in getaddrinfo_error::main () at src/main.rs:4