aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/syscall_linux.go
diff options
context:
space:
mode:
authorAlbert Sundjaja <albertsundjaja@gmail.com>2025-02-22 23:02:57 +0000
committerGopher Robot <gobot@golang.org>2025-02-24 09:43:24 -0800
commitfda918389947d32e854ddfc8c972b88bd31369c4 (patch)
tree26dadf50d4d8f6555dad187a5c949ded5ed600a0 /src/syscall/syscall_linux.go
parente382bf5b322c9814e910212ebd19907b68606c49 (diff)
downloadgo-fda918389947d32e854ddfc8c972b88bd31369c4.tar.xz
syscall: allow \x00-prefixed unix abstract socket to use full path length
Fixes #70893 Change-Id: Ia0aaa497dad335fe962d52d3f115d26e8046e36f GitHub-Last-Rev: 7dd663678d8aecdfac94541a570dfbd1aa2577e7 GitHub-Pull-Request: golang/go#71851 Reviewed-on: https://go-review.googlesource.com/c/go/+/650875 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/syscall/syscall_linux.go')
-rw-r--r--src/syscall/syscall_linux.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go
index 57d84748fe..d733ca9bf9 100644
--- a/src/syscall/syscall_linux.go
+++ b/src/syscall/syscall_linux.go
@@ -550,23 +550,29 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
if n > len(sa.raw.Path) {
return nil, 0, EINVAL
}
- if n == len(sa.raw.Path) && name[0] != '@' {
+ // Abstract addresses start with NUL.
+ // '@' is also a valid way to specify abstract addresses.
+ isAbstract := n > 0 && (name[0] == '@' || name[0] == '\x00')
+
+ // Non-abstract named addresses are NUL terminated.
+ // The length can't use the full capacity as we need to add NUL.
+ if n == len(sa.raw.Path) && !isAbstract {
return nil, 0, EINVAL
}
sa.raw.Family = AF_UNIX
for i := 0; i < n; i++ {
sa.raw.Path[i] = int8(name[i])
}
- // length is family (uint16), name, NUL.
- sl := _Socklen(2)
- if n > 0 {
- sl += _Socklen(n) + 1
- }
- if sa.raw.Path[0] == '@' || (sa.raw.Path[0] == 0 && sl > 3) {
- // Check sl > 3 so we don't change unnamed socket behavior.
+ // Length is family + name (+ NUL if non-abstract).
+ // Family is of type uint16 (2 bytes).
+ sl := _Socklen(2 + n)
+ if isAbstract {
+ // Abstract addresses are not NUL terminated.
+ // We rewrite '@' prefix to NUL here.
sa.raw.Path[0] = 0
- // Don't count trailing NUL for abstract address.
- sl--
+ } else if n > 0 {
+ // Add NUL for non-abstract named addresses.
+ sl++
}
return unsafe.Pointer(&sa.raw), sl, nil