std: fix unix socket address truncation without a trailing NUL - #160416
Conversation
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
getsockname(2) and friends do not count the trailing NUL in the length they report on freebsd, netbsd and qnx, and a caller may bind(2) without one anywhere, so shortening the path by one byte dropped its last character. scan for the NUL within the reported length instead, which is the rule unix(7) gives and subsumes the qnx case the old cfg handled. Fixes rust-lang#118925
|
|
I'm unfamiliar with this level of OS detail. @rustbot reroll |
| if cfg!(any(target_os = "qnx", target_env = "nto71")) { len } else { len - 1 }; | ||
| // linux adds a trailing NUL and counts it in the length, freebsd, netbsd | ||
| // and qnx do not, and a caller may bind(2) without one either. unix(7) | ||
| // gives the portable rule: strnlen(sun_path, len - offsetof(sun_path)) |
There was a problem hiding this comment.
Should this also adjust
rust/library/std/src/os/unix/net/addr.rs
Lines 57 to 63 in 771916f
There was a problem hiding this comment.
no because only the inbound one was a parsing bug, "oddly" enough QNX has it right using len (because this platform excludes the NULL terminator). As for the 'cfg' part, it is still needed as len is fed to bind where SUN_LEN for QNX is a real kernel-facing difference.
|
@bors r+ |
std: fix unix socket address truncation without a trailing NUL getsockname(2) and friends do not count the trailing NUL in the length they report on freebsd, netbsd and qnx, and a caller may bind(2) without one anywhere, so shortening the path by one byte dropped its last character. scan for the NUL within the reported length instead, which is the rule unix(7) gives and subsumes the qnx case the old cfg handled. Fixes rust-lang#118925
…uwer Rollup of 17 pull requests Successful merges: - #160529 (Upgrade and deduplicate dependencies) - #161017 (Library: enforce clippy deref lints in CI) - #160416 (std: fix unix socket address truncation without a trailing NUL) - #161006 ([CI] Build newer `binutils` before building `gcc`) - #161141 (Add documentation for BPF targets) - #161157 (bootstrap: Move several items out of the crate root) - #161185 (std: guard against unwinds in queue-based `Once`) - #161186 (miri subtree update) - #159855 (std: retry waitid on EINTR in the pidfd wait path) - #161053 (Add regression test for borrow of array drop type in const) - #161073 (Add regression test for path printing with infinitely many visible names) - #161099 (Add regression test for unstable def_ident_span fingerprint with incremental recompilation) - #161103 (cleanup: rip out unnecessary `iter().last()` and `iter().next()`) - #161136 (Add BPF test for Rust ABI stack arguments) - #161146 (Switch to c8a EC2 runner for auto merges) - #161148 ([rustdoc] Put back one removed flaky GUI test (which hopefully isn't flaky anymore)) - #161181 (Add back flaky gui rustdoc test `tests/rustdoc-gui/headers-color.goml`)
std: fix unix socket address truncation without a trailing NUL getsockname(2) and friends do not count the trailing NUL in the length they report on freebsd, netbsd and qnx, and a caller may bind(2) without one anywhere, so shortening the path by one byte dropped its last character. scan for the NUL within the reported length instead, which is the rule unix(7) gives and subsumes the qnx case the old cfg handled. Fixes rust-lang#118925
…uwer Rollup of 17 pull requests Successful merges: - #161017 (Library: enforce clippy deref lints in CI) - #160416 (std: fix unix socket address truncation without a trailing NUL) - #161006 ([CI] Build newer `binutils` before building `gcc`) - #161141 (Add documentation for BPF targets) - #161157 (bootstrap: Move several items out of the crate root) - #161185 (std: guard against unwinds in queue-based `Once`) - #161186 (miri subtree update) - #159855 (std: retry waitid on EINTR in the pidfd wait path) - #160478 (diagnostics: Suggest fn binding type for unstable closure for<> binders) - #161053 (Add regression test for borrow of array drop type in const) - #161073 (Add regression test for path printing with infinitely many visible names) - #161099 (Add regression test for unstable def_ident_span fingerprint with incremental recompilation) - #161103 (cleanup: rip out unnecessary `iter().last()` and `iter().next()`) - #161136 (Add BPF test for Rust ABI stack arguments) - #161146 (Switch to c8a EC2 runner for auto merges) - #161148 ([rustdoc] Put back one removed flaky GUI test (which hopefully isn't flaky anymore)) - #161181 (Add back flaky gui rustdoc test `tests/rustdoc-gui/headers-color.goml`)
Rollup merge of #160416 - devnexen:gh118925, r=Mark-Simulacrum std: fix unix socket address truncation without a trailing NUL getsockname(2) and friends do not count the trailing NUL in the length they report on freebsd, netbsd and qnx, and a caller may bind(2) without one anywhere, so shortening the path by one byte dropped its last character. scan for the NUL within the reported length instead, which is the rule unix(7) gives and subsumes the qnx case the old cfg handled. Fixes #118925
…uwer Rollup of 17 pull requests Successful merges: - rust-lang/rust#161017 (Library: enforce clippy deref lints in CI) - rust-lang/rust#160416 (std: fix unix socket address truncation without a trailing NUL) - rust-lang/rust#161006 ([CI] Build newer `binutils` before building `gcc`) - rust-lang/rust#161141 (Add documentation for BPF targets) - rust-lang/rust#161157 (bootstrap: Move several items out of the crate root) - rust-lang/rust#161185 (std: guard against unwinds in queue-based `Once`) - rust-lang/rust#161186 (miri subtree update) - rust-lang/rust#159855 (std: retry waitid on EINTR in the pidfd wait path) - rust-lang/rust#160478 (diagnostics: Suggest fn binding type for unstable closure for<> binders) - rust-lang/rust#161053 (Add regression test for borrow of array drop type in const) - rust-lang/rust#161073 (Add regression test for path printing with infinitely many visible names) - rust-lang/rust#161099 (Add regression test for unstable def_ident_span fingerprint with incremental recompilation) - rust-lang/rust#161103 (cleanup: rip out unnecessary `iter().last()` and `iter().next()`) - rust-lang/rust#161136 (Add BPF test for Rust ABI stack arguments) - rust-lang/rust#161146 (Switch to c8a EC2 runner for auto merges) - rust-lang/rust#161148 ([rustdoc] Put back one removed flaky GUI test (which hopefully isn't flaky anymore)) - rust-lang/rust#161181 (Add back flaky gui rustdoc test `tests/rustdoc-gui/headers-color.goml`)
getsockname(2) and friends do not count the trailing NUL in the length they report on freebsd, netbsd and qnx, and a caller may bind(2) without one anywhere, so shortening the path by one byte dropped its last character. scan for the NUL within the reported length instead, which is the rule unix(7) gives and subsumes the qnx case the old cfg handled.
Fixes #118925