Skip to content

Commit

Permalink
syscall: stop counting trailing NUL for abstract addresses starting w…
Browse files Browse the repository at this point in the history
…ith NUL

Changes trailing-NUL-counting behavior for abstract addresses
starting with the NUL character to be the same as abstract
addresses starting with the @ character.

For #63579.

Change-Id: I206e4d0d808396998cb7d92a9e26dda854cb1248
GitHub-Last-Rev: 0ff0a9c
GitHub-Pull-Request: #63580
Reviewed-on: https://go-review.googlesource.com/c/go/+/535776
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
  • Loading branch information
F Y authored and gopherbot committed Oct 20, 2023
1 parent c75a617 commit 3de6033
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/syscall/syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
if n > 0 {
sl += _Socklen(n) + 1
}
if sa.raw.Path[0] == '@' {
if sa.raw.Path[0] == '@' || (sa.raw.Path[0] == 0 && sl > 3) {
// Check sl > 3 so we don't change unnamed socket behavior.
sa.raw.Path[0] = 0
// Don't count trailing NUL for abstract address.
sl--
Expand Down
3 changes: 2 additions & 1 deletion src/syscall/syscall_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
if n > 0 {
sl += _Socklen(n) + 1
}
if sa.raw.Path[0] == '@' {
if sa.raw.Path[0] == '@' || (sa.raw.Path[0] == 0 && sl > 3) {
// Check sl > 3 so we don't change unnamed socket behavior.
sa.raw.Path[0] = 0
// Don't count trailing NUL for abstract address.
sl--
Expand Down
3 changes: 2 additions & 1 deletion src/syscall/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) {
if n > 0 {
sl += int32(n) + 1
}
if sa.raw.Path[0] == '@' {
if sa.raw.Path[0] == '@' || (sa.raw.Path[0] == 0 && sl > 3) {
// Check sl > 3 so we don't change unnamed socket behavior.
sa.raw.Path[0] = 0
// Don't count trailing NUL for abstract address.
sl--
Expand Down

0 comments on commit 3de6033

Please sign in to comment.