Skip to content

Reject null bytes in Unix socket pathnames - #682

Open
omrzk wants to merge 2 commits into
rust-lang:masterfrom
omrzk:fix/unix-address-conversion-681
Open

omrzk wants to merge 2 commits into
rust-lang:masterfrom
omrzk:fix/unix-address-conversion-681

Conversation

@omrzk

@omrzk omrzk commented Nov 2, 2026 •

Copy link
Copy Markdown

SockAddr::unix accepts pathname bytes containing NUL, which operating systems can truncate and the standard library rejects. Reject those pathnames with InvalidInput in both constructor backends. Preserve the existing leading-NUL address behavior, including Linux abstract names containing additional zero bytes.

Retain a fallible as_unix conversion for addresses initialized from raw storage: a full-size, null-terminated sockaddr_un can still include padding NULs in the pathname exposed by as_pathname. The new raw-storage fixture covers that conversion boundary.

Fixes #681.

Validation: constructor rejection fails on the previous PR head and passes after the change; ordinary/non-UTF-8 paths, empty/unnamed addresses and abstract names are preserved. Default and all-feature suites pass in debug and release (11 unit tests; 47 default or 82 all-feature integration tests; 7 or 8 doc tests). Formatting, all-target/all-feature Clippy with warnings denied, docs and all-target/all-feature Windows MSVC and FreeBSD compile checks pass. Runtime tests were run on Linux; the Windows/FreeBSD checks were compilation only.

@Thomasdezeeuw

Copy link
Copy Markdown
Contributor

I don't think is the right approach, we should look into disallowing the creation of address with internal null bytes. Most OS, being C based, don't deal well with internal null bytes.

@omrzk omrzk changed the title Avoid panicking when a Unix address cannot convert to std Reject null bytes in Unix socket pathnames Nov 2, 2026
@omrzk

omrzk commented Nov 2, 2026

Copy link
Copy Markdown
Author

Updated the existing branch to reject NUL bytes in pathname addresses in both constructor backends. Leading-NUL addresses retain their existing behavior, including interior zeros in Linux abstract names.

I kept the fallible as_unix conversion because raw initializers can still provide a full-size null-terminated sockaddr_un whose padding is included by as_pathname; a separate raw-storage regression covers that case. The constructor regression fails on the previous PR head and passes with this change. Final test and cross-compilation results are recorded in the updated description.

This branch has not been deployed

No deployments
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 this pull request may close these issues.

SockAddr::as_unix panics on a path with an interior null byte

2 participants