syscall: Fix handling of Unix domain @ addresses.

From-SVN: r193783
This commit is contained in:
Ian Lance Taylor 2012-11-24 20:46:59 +00:00
parent f246eadc0a
commit 40ff695f5c
2 changed files with 6 additions and 2 deletions

View File

@ -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) {

View File

@ -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++
}