Skip to content

std: fix unix socket address truncation without a trailing NUL - #160416

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
devnexen:gh118925
Aug 17, 2026
Merged

std: fix unix socket address truncation without a trailing NUL#160416
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
devnexen:gh118925

Conversation

@devnexen

@devnexen devnexen commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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

@rustbot rustbot added O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 3, 2026
@rustbot

rustbot commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from 6 candidates

@rustbot

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
@rustbot

rustbot commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@jhpratt

jhpratt commented Aug 5, 2026

Copy link
Copy Markdown
Member

I'm unfamiliar with this level of OS detail.

@rustbot reroll

@rustbot rustbot assigned Mark-Simulacrum and unassigned jhpratt Aug 5, 2026
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))

@Mark-Simulacrum Mark-Simulacrum Aug 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also adjust

// on QNX7.1 and QNX8 the `len` value returned by the SUN_LEN
// macro in its libc does not include the null byte in the count so
// don't add it here to match what a C program passes to bind(2) and
// similar functions
if cfg!(not(any(target_os = "qnx", target_env = "nto71"))) {
len += 1
}
? Haven't traced the code but went looking for the QNX modifications which were in #158697.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot ready

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 8, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 15, 2026
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e96993c has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 16, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 16, 2026
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
rust-bors Bot pushed a commit that referenced this pull request Aug 16, 2026
…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`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 16, 2026
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
rust-bors Bot pushed a commit that referenced this pull request Aug 16, 2026
…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`)
@rust-bors
rust-bors Bot merged commit 71b938c into rust-lang:main Aug 17, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Aug 17, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 17, 2026
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
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Aug 17, 2026
…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`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-unix Operating system: Unix-like S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnixDatagram::local_addr wrongly assumes the presence of a trailing NUL

4 participants