diff --git a/libgo/go/syscall/socket.go b/libgo/go/syscall/socket.go index 819e70a46d3..3aa92012f08 100644 --- a/libgo/go/syscall/socket.go +++ b/libgo/go/syscall/socket.go @@ -87,12 +87,16 @@ func (sa *SockaddrUnix) sockaddr() (*RawSockaddrAny, Socklen_t, error) { for i := 0; i < n; i++ { sa.raw.Path[i] = int8(name[i]) } + // length is family (uint16), name, NUL. + sl := 2 + Socklen_t(n) + 1 if sa.raw.Path[0] == '@' { sa.raw.Path[0] = 0 + // Don't count trailing NUL for abstract address. + sl-- } // length is family (uint16), name, NUL. - return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), 2 + Socklen_t(n) + 1, nil + return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), sl, nil } func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) { diff --git a/libgo/go/syscall/socket_linux.go b/libgo/go/syscall/socket_linux.go index cd7d6eb98b9..49a1625d08d 100644 --- a/libgo/go/syscall/socket_linux.go +++ b/libgo/go/syscall/socket_linux.go @@ -103,7 +103,7 @@ func (sa *RawSockaddrUnix) getLen() (int, error) { // to be uninterpreted fixed-size binary blobs--but // everyone uses this convention. n := 0 - for n < len(sa.Path)-3 && sa.Path[n] != 0 { + for n < len(sa.Path) && sa.Path[n] != 0 { n++ }