Repository navigation
Conversation
|
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. |
|
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 |
| /// Returns this address as Unix `SocketAddr` if it is an `AF_UNIX` pathname | ||
| /// address, otherwise returns `None`. | ||
| /// address that can be represented by the standard library, otherwise returns | ||
| /// `None`. | ||
| pub fn as_unix(&self) -> Option<std::os::unix::net::SocketAddr> { | ||
| let path = self.as_pathname()?; | ||
| // SAFETY: we can represent this as a valid pathname, then so can the | ||
| // standard library. | ||
| Some(std::os::unix::net::SocketAddr::from_pathname(path).unwrap()) | ||
| std::os::unix::net::SocketAddr::from_pathname(path).ok() |
There was a problem hiding this comment.
I don't see where you changed whether this conversion can fail.
There was a problem hiding this comment.
The return type was already Option; the change is replacing Some(SocketAddr::from_pathname(path).unwrap()) with SocketAddr::from_pathname(path).ok(). A standard-library rejection now returns None instead of panicking.
The constructor checks cover normal pathname creation. socket_address_unix_padded_raw_pathname covers the remaining raw-storage path: it supplies a full-size, NUL-padded sockaddr_un, checks that as_pathname() still exposes the padding, and verifies that as_unix() returns None. That is why I kept the fallible conversion after adding constructor validation.
SockAddr::unixaccepts pathname bytes containing NUL, which operating systems can truncate and the standard library rejects. Reject those pathnames withInvalidInputin both constructor backends. Preserve the existing leading-NUL address behavior, including Linux abstract names containing additional zero bytes.Retain a fallible
as_unixconversion for addresses initialized from raw storage: a full-size, null-terminatedsockaddr_uncan still include padding NULs in the pathname exposed byas_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.