1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:14:43 -07:00

internal/syscall/windows: change WSAMsg.Name type

The problem was discovered while running

go test -a -short -gcflags=all=-d=checkptr -run=TestUDPConnSpecificMethods net

WSAMsg is type defined by Windows. And WSAMsg.Name could point to two
different structures for IPv4 and IPV6 sockets.

Currently WSAMsg.Name is declared as *syscall.RawSockaddrAny. But that
violates

(1) Conversion of a *T1 to Pointer to *T2.

rule of

https://golang.org/pkg/unsafe/#Pointer

When we convert *syscall.RawSockaddrInet4 into *syscall.RawSockaddrAny,
syscall.RawSockaddrInet4 and syscall.RawSockaddrAny do not share an
equivalent memory layout.

Same for *syscall.SockaddrInet6 into *syscall.RawSockaddrAny.

This CL changes WSAMsg.Name type to *syscall.Pointer. syscall.Pointer
length is 0, and that at least makes type checker happy.

After this change I was able to run

go test -a -short -gcflags=all=-d=checkptr std cmd

without type checker complaining.

Updates #34972

Change-Id: Ic5c2321c20abd805c687ee16ef6f643a2f8cd93f
Reviewed-on: https://go-review.googlesource.com/c/go/+/222457
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Alex Brainman 2020-03-07 11:08:06 +11:00
parent 9667294d8f
commit 801cd7c84d
2 changed files with 3 additions and 3 deletions

View File

@ -999,7 +999,7 @@ func (fd *FD) ReadMsg(p []byte, oob []byte) (int, int, int, syscall.Sockaddr, er
o := &fd.rop
o.InitMsg(p, oob)
o.rsa = new(syscall.RawSockaddrAny)
o.msg.Name = o.rsa
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
o.msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
n, err := execIO(o, func(o *operation) error {
return windows.WSARecvMsg(o.fd.Sysfd, &o.msg, &o.qty, &o.o, nil)
@ -1030,7 +1030,7 @@ func (fd *FD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (int, int, err
if err != nil {
return 0, 0, err
}
o.msg.Name = (*syscall.RawSockaddrAny)(rsa)
o.msg.Name = (syscall.Pointer)(rsa)
o.msg.Namelen = len
}
n, err := execIO(o, func(o *operation) error {

View File

@ -176,7 +176,7 @@ var sendRecvMsgFunc struct {
}
type WSAMsg struct {
Name *syscall.RawSockaddrAny
Name syscall.Pointer
Namelen int32
Buffers *syscall.WSABuf
BufferCount uint32