diff options
author | Alex Brainman <alex.brainman@gmail.com> | 2020-02-25 18:44:55 +1100 |
---|---|---|
committer | Alex Brainman <alex.brainman@gmail.com> | 2020-04-02 09:00:34 +0000 |
commit | 9667294d8f5c8c6e2c48efa1ced98cb7e9cfaf51 (patch) | |
tree | fdf4049b354a9b068159fe1006a9bbb610bf7e61 | |
parent | 95773ab9b053edc43ba07a182f3d5e0e29775a45 (diff) | |
download | go-9667294d8f5c8c6e2c48efa1ced98cb7e9cfaf51.tar.gz go-9667294d8f5c8c6e2c48efa1ced98cb7e9cfaf51.zip |
syscall: fix windows WSASendto -d=checkptr violation
WSASendto converts unsafe.Pointer to *syscall.RawSockaddrAny. But that
violates every rule of
https://golang.org/pkg/unsafe/#Pointer
Implement WSASendto by calling Windows WSASendTo API by calling
syscall.Syscall9 directly. This allows us to comply with
(4) Conversion of a Pointer to a uintptr when calling syscall.Syscall
rule.
After this change, this commands succeeds:
go test -a -short -gcflags=all=-d=checkptr -run=TestPacketConn net
Updates #34972
Change-Id: Ib9a810bedf9e05251b7d3c7f69e15bfbd177ac62
Reviewed-on: https://go-review.googlesource.com/c/go/+/220544
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r-- | src/syscall/syscall_windows.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index 950c281e4d..922cf2cb2e 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -871,11 +871,19 @@ func Shutdown(fd Handle, how int) (err error) { } func WSASendto(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to Sockaddr, overlapped *Overlapped, croutine *byte) (err error) { - rsa, l, err := to.sockaddr() + rsa, len, err := to.sockaddr() if err != nil { return err } - return WSASendTo(s, bufs, bufcnt, sent, flags, (*RawSockaddrAny)(unsafe.Pointer(rsa)), l, overlapped, croutine) + r1, _, e1 := Syscall9(procWSASendTo.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(rsa)), uintptr(len), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) + if r1 == socket_error { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = EINVAL + } + } + return err } func LoadGetAddrInfo() error { |