Allocated SocketAddrUnix::path() with correct length#1372
Merged
sunfishcode merged 1 commit intobytecodealliance:sunfishcode/nonterminated-sun-pathfrom Mar 3, 2025
Merged
Conversation
ae87066 to
d183318
Compare
Using `.to_owned()` + `.push()` will cause a reallocation, because the initially allocated array with be one byte too short. We can use `CString::from_vec_with_nul_unchecked()` because it is a known invariant that the input does not contain any `NUL`s, not even the terminating `NUL`.
d183318 to
0d0ba07
Compare
Member
|
Cool, thanks! |
4e2f0ac
into
bytecodealliance:sunfishcode/nonterminated-sun-path
sunfishcode
added a commit
that referenced
this pull request
Mar 3, 2025
* Handle non-NUL-terminated strings in `SocketAddrUnix`. Unix-domain socket address can be long enough that the NUL terminator does not fit. Handle this case by making `path()` return a `Cow<CStr>` and adding a NUL terminator as needed. Also add a `path_bytes()` function for returning the raw bytes. Fixes #1316. * Allocated `SocketAddrUnix::path()` with correct length (#1372) Using `.to_owned()` + `.push()` will cause a reallocation, because the initially allocated array with be one byte too short. We can use `CString::from_vec_with_nul_unchecked()` because it is a known invariant that the input does not contain any `NUL`s, not even the terminating `NUL`. --------- Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Using
.to_owned()+.push()will cause a reallocation, because the initially allocated array with be one byte too short.We can use
CString::from_vec_with_nul_unchecked()because it is a known invariant that the input does not contain anyNULs, not even the terminatingNUL.@sunfishcode, I hope it's okay that I post a PR to a PR. It was easier to implement the change in a commit than to add multiple suggestions in #1371.