Skip to content

Commit

Permalink
internal/syscall/windows: change WSAMsg.Name type
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
alexbrainman committed Apr 2, 2020
1 parent 9667294 commit 801cd7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/internal/poll/fd_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/syscall/windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ var sendRecvMsgFunc struct {
}

type WSAMsg struct {
Name *syscall.RawSockaddrAny
Name syscall.Pointer
Namelen int32
Buffers *syscall.WSABuf
BufferCount uint32
Expand Down

0 comments on commit 801cd7c

Please sign in to comment.