]> Cypherpunks.ru repositories - gostls13.git/commitdiff
syscall: stop counting trailing NUL for abstract addresses starting with NUL
authorF Y <x1f604@gmail.com>
Tue, 17 Oct 2023 21:59:17 +0000 (21:59 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 20 Oct 2023 18:13:19 +0000 (18:13 +0000)
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: 0ff0a9c938a4b57cdc30b1c4f0c058108a241df8
GitHub-Pull-Request: golang/go#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>
src/syscall/syscall_linux.go
src/syscall/syscall_solaris.go
src/syscall/syscall_windows.go

index ad72a1d018563c6d9e5a076b95858176fb78821c..96ad4fbe3f4208513b12e595bdbdbb4e77e5f666 100644 (file)
@@ -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--
index 243794940ed4fa7c3d24cee49bdd98f37e83d99d..28d3727db66f4ad198ce5d7a39400563ff61d112 100644 (file)
@@ -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--
index 8229e252d9e8e0ecfe161a57b18979b7fed76844..33876c7fe035165b24a8eea316eb4d9bc69d663c 100644 (file)
@@ -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--