Darwin: fix sockaddr_un overflow in makeAddressUnix for long paths - #230
Merged
swhitty merged 1 commit intoJul 22, 2026
Conversation
Truncate paths to 103 bytes and always NUL-terminate sun_path, which Darwin <sys/un.h> declares as char sun_path[104]. Previously strncpy was bounded by sun_len (up to 106), writing past the end of the struct. Also fix the same off-by-one in maximumPathLengthForUnixDomainSocket, which copied 105 bytes into the 104-byte field (caught by ASan), and add round-trip tests for max-length and overlong paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #230 +/- ##
==========================================
+ Coverage 92.88% 93.00% +0.11%
==========================================
Files 71 71
Lines 3727 3730 +3
==========================================
+ Hits 3462 3469 +7
+ Misses 265 261 -4 ☔ View full report in Codecov by Harness. |
swhitty
approved these changes
Jul 22, 2026
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.
Summary
Socket.makeAddressUnix(path:)on Darwin clamped the path to 104 bytes but boundedstrncpybysun_len(up to 106), writing past the end ofsun_path— which Darwin<sys/un.h>declares aschar sun_path[104]. Paths ≥ 102 bytes overflowed the struct.sun_pathis always NUL-terminated, soString(cString:)andunlink()read back a valid C string.maximumPathLengthForUnixDomainSockettest, which computed the capacity from struct arithmetic that omittedsun_lenand copied 105 bytes into the 104-byte field (caught by AddressSanitizer).Test plan
swift test --filter SocketAddressTests— 20/20 pass.swift test --sanitize address --filter SocketAddressTests— clean, no ASan reports.🤖 Generated with Claude Code