diff options
Diffstat (limited to 'libgo/go/syscall/socket.go')
-rw-r--r-- | libgo/go/syscall/socket.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/libgo/go/syscall/socket.go b/libgo/go/syscall/socket.go index 93bbc38..d3ff636 100644 --- a/libgo/go/syscall/socket.go +++ b/libgo/go/syscall/socket.go @@ -79,7 +79,7 @@ type SockaddrUnix struct { func (sa *SockaddrUnix) sockaddr() (*RawSockaddrAny, Socklen_t, error) { name := sa.Name n := len(name) - if n >= len(sa.raw.Path) { + if n > len(sa.raw.Path) { return nil, 0, EINVAL } sa.raw.Family = AF_UNIX @@ -93,6 +93,11 @@ func (sa *SockaddrUnix) sockaddr() (*RawSockaddrAny, Socklen_t, error) { sl += Socklen_t(n) + 1 } sl = sa.raw.adjustAbstract(sl) + // Check again after adjustAbstract adjusts the length. + // This is testing whether the +1 for NUL puts us out of range. + if sl-2 > Socklen_t(len(sa.raw.Path)) { + return nil, 0, EINVAL + } // length is family (uint16), name, NUL. return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), sl, nil @@ -343,8 +348,13 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from } var dummy byte if len(oob) > 0 { + var sockType int + sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE) + if err != nil { + return + } // receive at least one normal byte - if len(p) == 0 { + if sockType != SOCK_DGRAM && len(p) == 0 { iov.Base = &dummy iov.SetLen(1) } @@ -390,8 +400,13 @@ func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) } var dummy byte if len(oob) > 0 { + var sockType int + sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE) + if err != nil { + return 0, err + } // send at least one normal byte - if len(p) == 0 { + if sockType != SOCK_DGRAM && len(p) == 0 { iov.Base = &dummy iov.SetLen(1) } |