summaryrefslogtreecommitdiff
path: root/libgo/go/syscall/sockcmsg_unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/syscall/sockcmsg_unix.go')
-rw-r--r--libgo/go/syscall/sockcmsg_unix.go18
1 files changed, 8 insertions, 10 deletions
diff --git a/libgo/go/syscall/sockcmsg_unix.go b/libgo/go/syscall/sockcmsg_unix.go
index 951bc18fcdf..03c17908ec4 100644
--- a/libgo/go/syscall/sockcmsg_unix.go
+++ b/libgo/go/syscall/sockcmsg_unix.go
@@ -13,7 +13,7 @@ import (
"unsafe"
)
-// Round the length of a raw sockaddr up to align it propery.
+// Round the length of a raw sockaddr up to align it properly.
func cmsgAlignOf(salen int) int {
salign := int(sizeofPtr)
// NOTE: It seems like 64-bit Darwin kernel still requires 32-bit
@@ -26,9 +26,6 @@ func cmsgAlignOf(salen int) int {
if runtime.GOOS == "solaris" {
salign = 4
}
- if salen == 0 {
- return salign
- }
return (salen + salign - 1) & ^(salign - 1)
}
@@ -45,7 +42,7 @@ func CmsgSpace(datalen int) int {
}
func cmsgData(h *Cmsghdr) unsafe.Pointer {
- return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + SizeofCmsghdr)
+ return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + uintptr(cmsgAlignOf(SizeofCmsghdr)))
}
// SocketControlMessage represents a socket control message.
@@ -58,14 +55,15 @@ type SocketControlMessage struct {
// messages.
func ParseSocketControlMessage(b []byte) ([]SocketControlMessage, error) {
var msgs []SocketControlMessage
- for len(b) >= CmsgLen(0) {
- h, dbuf, err := socketControlMessageHeaderAndData(b)
+ i := 0
+ for i+CmsgLen(0) <= len(b) {
+ h, dbuf, err := socketControlMessageHeaderAndData(b[i:])
if err != nil {
return nil, err
}
- m := SocketControlMessage{Header: *h, Data: dbuf[:int(h.Len)-cmsgAlignOf(SizeofCmsghdr)]}
+ m := SocketControlMessage{Header: *h, Data: dbuf}
msgs = append(msgs, m)
- b = b[cmsgAlignOf(int(h.Len)):]
+ i += cmsgAlignOf(int(h.Len))
}
return msgs, nil
}
@@ -75,7 +73,7 @@ func socketControlMessageHeaderAndData(b []byte) (*Cmsghdr, []byte, error) {
if h.Len < SizeofCmsghdr || int(h.Len) > len(b) {
return nil, nil, EINVAL
}
- return h, b[cmsgAlignOf(SizeofCmsghdr):], nil
+ return h, b[cmsgAlignOf(SizeofCmsghdr):h.Len], nil
}
// UnixRights encodes a set of open file descriptors into a socket