]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: fix windows WSASendto -d=checkptr violation
authorAlex Brainman <alex.brainman@gmail.com>
Tue, 25 Feb 2020 07:44:55 +0000 (18:44 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 2 Apr 2020 09:00:34 +0000 (09:00 +0000)
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>
src/syscall/syscall_windows.go

index 950c281e4db4fce2f66efd6f12cf4d986aacc0d2..922cf2cb2efdb3c9f98b18b511393c380550b6a5 100644 (file)
@@ -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 {