]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: don't pass non-nil WSAMsg.Name with 0 namelen on windows
authordatabase64128 <free122448@hotmail.com>
Fri, 22 Aug 2025 06:53:45 +0000 (14:53 +0800)
committerGopher Robot <gobot@golang.org>
Fri, 22 Aug 2025 21:46:56 +0000 (14:46 -0700)
CL 692436 changed WriteMsgInet{4,6} on windows to pass a zero namelen
when the sockaddr is nil. Turns out Windows also requires name to be
nil when namelen is 0.

With this commit, WriteMsgInet4 and WriteMsgInet6 now nicely align with
WriteMsg.

For #74841

Change-Id: Ifadee2d12d9bce2411f11a0e12b9fa2b3d71990e
Reviewed-on: https://go-review.googlesource.com/c/go/+/698395
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>

src/internal/poll/fd_windows.go

index 5d6d78d8bb4378103e0af1afa9b989688276268d..87cd67ecf68a404c2ed5b976038d70acea5ce70b 100644 (file)
@@ -1419,16 +1419,14 @@ func (fd *FD) WriteMsgInet4(p []byte, oob []byte, sa *syscall.SockaddrInet4) (in
        defer fd.writeUnlock()
 
        o := &fd.wop
-       if o.rsa == nil {
-               o.rsa = new(syscall.RawSockaddrAny)
-       }
-       var nameLen int32
+       msg := newWSAMsg(p, oob, 0)
        if sa != nil {
-               nameLen = sockaddrInet4ToRaw(o.rsa, sa)
+               if o.rsa == nil {
+                       o.rsa = new(syscall.RawSockaddrAny)
+               }
+               msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
+               msg.Namelen = sockaddrInet4ToRaw(o.rsa, sa)
        }
-       msg := newWSAMsg(p, oob, 0)
-       msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
-       msg.Namelen = nameLen
        n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
                err = windows.WSASendMsg(fd.Sysfd, &msg, 0, nil, &o.o, nil)
                return qty, err
@@ -1448,16 +1446,14 @@ func (fd *FD) WriteMsgInet6(p []byte, oob []byte, sa *syscall.SockaddrInet6) (in
        defer fd.writeUnlock()
 
        o := &fd.wop
-       if o.rsa == nil {
-               o.rsa = new(syscall.RawSockaddrAny)
-       }
        msg := newWSAMsg(p, oob, 0)
-       var nameLen int32
        if sa != nil {
-               nameLen = sockaddrInet6ToRaw(o.rsa, sa)
+               if o.rsa == nil {
+                       o.rsa = new(syscall.RawSockaddrAny)
+               }
+               msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
+               msg.Namelen = sockaddrInet6ToRaw(o.rsa, sa)
        }
-       msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
-       msg.Namelen = nameLen
        n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
                err = windows.WSASendMsg(fd.Sysfd, &msg, 0, nil, &o.o, nil)
                return qty, err