From: database64128 Date: Fri, 22 Aug 2025 06:53:45 +0000 (+0800) Subject: internal/poll: don't pass non-nil WSAMsg.Name with 0 namelen on windows X-Git-Tag: go1.26rc1~1035 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=78a05c541f;p=gostls13.git internal/poll: don't pass non-nil WSAMsg.Name with 0 namelen on windows 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 Reviewed-by: Sean Liao Auto-Submit: Sean Liao LUCI-TryBot-Result: Go LUCI Reviewed-by: Carlos Amedee Auto-Submit: Damien Neil --- diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index 5d6d78d8bb..87cd67ecf6 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -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