Commit ef18d6a9 authored by Matthew Dempsky's avatar Matthew Dempsky

syscall: avoid "just past the end" pointers in UnixRights

Caught with -d=checkptr.

Updates #22218.

Change-Id: Ic0fcff4d2c8d83e4e7f5e0c6d01f03c9c7766c6d
Reviewed-on: https://go-review.googlesource.com/c/go/+/201617
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 3972f97d
...@@ -17,7 +17,7 @@ func UnixCredentials(ucred *Ucred) []byte { ...@@ -17,7 +17,7 @@ func UnixCredentials(ucred *Ucred) []byte {
h.Level = SOL_SOCKET h.Level = SOL_SOCKET
h.Type = SCM_CREDENTIALS h.Type = SCM_CREDENTIALS
h.SetLen(CmsgLen(SizeofUcred)) h.SetLen(CmsgLen(SizeofUcred))
*((*Ucred)(cmsgData(h))) = *ucred *(*Ucred)(h.data(0)) = *ucred
return b return b
} }
......
...@@ -50,8 +50,8 @@ func CmsgSpace(datalen int) int { ...@@ -50,8 +50,8 @@ func CmsgSpace(datalen int) int {
return cmsgAlignOf(SizeofCmsghdr) + cmsgAlignOf(datalen) return cmsgAlignOf(SizeofCmsghdr) + cmsgAlignOf(datalen)
} }
func cmsgData(h *Cmsghdr) unsafe.Pointer { func (h *Cmsghdr) data(offset uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + uintptr(cmsgAlignOf(SizeofCmsghdr))) return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + uintptr(cmsgAlignOf(SizeofCmsghdr)) + offset)
} }
// SocketControlMessage represents a socket control message. // SocketControlMessage represents a socket control message.
...@@ -94,10 +94,8 @@ func UnixRights(fds ...int) []byte { ...@@ -94,10 +94,8 @@ func UnixRights(fds ...int) []byte {
h.Level = SOL_SOCKET h.Level = SOL_SOCKET
h.Type = SCM_RIGHTS h.Type = SCM_RIGHTS
h.SetLen(CmsgLen(datalen)) h.SetLen(CmsgLen(datalen))
data := cmsgData(h) for i, fd := range fds {
for _, fd := range fds { *(*int32)(h.data(4 * uintptr(i))) = int32(fd)
*(*int32)(data) = int32(fd)
data = unsafe.Pointer(uintptr(data) + 4)
} }
return b return b
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment