Fix handling of abstract Unix socket addresses
* Don't truncate abstract addresses at second null. * Properly handle abstract addresses with length < 108 bytes. PiperOrigin-RevId: 209502703 Change-Id: I49053f2d18b5a78208c3f640c27dbbdaece4f1a9
This commit is contained in:
parent
1501400d9c
commit
47d5a12ce5
|
@ -153,9 +153,9 @@ func GetAddress(sfamily int, addr []byte) (tcpip.FullAddress, *syserr.Error) {
|
||||||
if len(path) > linux.UnixPathMax {
|
if len(path) > linux.UnixPathMax {
|
||||||
return tcpip.FullAddress{}, syserr.ErrInvalidArgument
|
return tcpip.FullAddress{}, syserr.ErrInvalidArgument
|
||||||
}
|
}
|
||||||
// Drop the terminating NUL (if one exists) and everything after it.
|
// Drop the terminating NUL (if one exists) and everything after
|
||||||
// Skip the first byte, which is NUL for abstract paths.
|
// it for filesystem (non-abstract) addresses.
|
||||||
if len(path) > 1 {
|
if len(path) > 0 && path[0] != 0 {
|
||||||
if n := bytes.IndexByte(path[1:], 0); n >= 0 {
|
if n := bytes.IndexByte(path[1:], 0); n >= 0 {
|
||||||
path = path[:n+1]
|
path = path[:n+1]
|
||||||
}
|
}
|
||||||
|
@ -743,22 +743,20 @@ func ConvertAddress(family int, addr tcpip.FullAddress) (interface{}, uint32) {
|
||||||
case linux.AF_UNIX:
|
case linux.AF_UNIX:
|
||||||
var out linux.SockAddrUnix
|
var out linux.SockAddrUnix
|
||||||
out.Family = linux.AF_UNIX
|
out.Family = linux.AF_UNIX
|
||||||
for i := 0; i < len([]byte(addr.Addr)); i++ {
|
l := len([]byte(addr.Addr))
|
||||||
|
for i := 0; i < l; i++ {
|
||||||
out.Path[i] = int8(addr.Addr[i])
|
out.Path[i] = int8(addr.Addr[i])
|
||||||
}
|
}
|
||||||
// Linux just returns the header for empty addresses.
|
|
||||||
if len(addr.Addr) == 0 {
|
|
||||||
return out, 2
|
|
||||||
}
|
|
||||||
// Linux returns the used length of the address struct (including the
|
// Linux returns the used length of the address struct (including the
|
||||||
// null terminator) for filesystem paths. The Family field is 2 bytes.
|
// null terminator) for filesystem paths. The Family field is 2 bytes.
|
||||||
// It is sometimes allowed to exclude the null terminator if the
|
// It is sometimes allowed to exclude the null terminator if the
|
||||||
// address length is the max. Abstract paths always return the full
|
// address length is the max. Abstract and empty paths always return
|
||||||
// length.
|
// the full exact length.
|
||||||
if out.Path[0] == 0 || len([]byte(addr.Addr)) == len(out.Path) {
|
if l == 0 || out.Path[0] == 0 || l == len(out.Path) {
|
||||||
return out, uint32(binary.Size(out))
|
return out, uint32(2 + l)
|
||||||
}
|
}
|
||||||
return out, uint32(3 + len(addr.Addr))
|
return out, uint32(3 + l)
|
||||||
case linux.AF_INET:
|
case linux.AF_INET:
|
||||||
var out linux.SockAddrInet
|
var out linux.SockAddrInet
|
||||||
copy(out.Addr[:], addr.Addr)
|
copy(out.Addr[:], addr.Addr)
|
||||||
|
|
Loading…
Reference in New Issue