net: correctly handle non-nil empty cmsg buffer on windows
Fixes #77875.
diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go
index 6875557..4fa912d 100644
--- a/src/internal/poll/fd_windows.go
+++ b/src/internal/poll/fd_windows.go
@@ -167,9 +167,11 @@
msg := wsaMsgPool.Get().(*windows.WSAMsg)
msg.Buffers.Len = uint32(len(p))
msg.Buffers.Buf = unsafe.SliceData(p)
- msg.Control = syscall.WSABuf{
- Len: uint32(len(oob)),
- Buf: unsafe.SliceData(oob),
+ if len(oob) > 0 {
+ msg.Control = syscall.WSABuf{
+ Len: uint32(len(oob)),
+ Buf: unsafe.SliceData(oob),
+ }
}
msg.Flags = uint32(flags)
if unconnected {
diff --git a/src/net/udpsock_test.go b/src/net/udpsock_test.go
index a79e9f8..1700eba 100644
--- a/src/net/udpsock_test.go
+++ b/src/net/udpsock_test.go
@@ -750,3 +750,45 @@
t.Errorf("conn.WriteMsgUDPAddrPort(buf, nil, daddr6) should have failed, but got no error")
}
}
+
+// TestReadWriteMsgUDPAddrPortEmptyCmsg verifies that ReadMsgUDPAddrPort and
+// WriteMsgUDPAddrPort won't fail when the cmsg buffer (the oob parameter) is
+// non-nil but empty.
+//
+// This is a regression test for https://golang.org/issue/77875.
+func TestReadWriteMsgUDPAddrPortEmptyCmsg(t *testing.T) {
+ switch runtime.GOOS {
+ case "plan9":
+ t.Skipf("not supported on %s", runtime.GOOS)
+ }
+
+ if !testableNetwork("udp4") {
+ t.Skipf("skipping: udp4 not available")
+ }
+
+ conn, err := ListenUDP("udp4", &UDPAddr{IP: IPv4(127, 0, 0, 1)})
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer conn.Close()
+
+ buf := make([]byte, 8)
+ cmsgBuf := make([]byte, 8)[:0]
+ daddr := conn.LocalAddr().(*UDPAddr).AddrPort()
+
+ _, cmsgn, err := conn.WriteMsgUDPAddrPort(buf, cmsgBuf, daddr)
+ if err != nil {
+ t.Fatalf("WriteMsgUDPAddrPort failed: %v", err)
+ }
+ if cmsgn != 0 {
+ t.Errorf("WriteMsgUDPAddrPort wrote %d cmsg bytes; want 0", cmsgn)
+ }
+
+ _, cmsgn, _, _, err = conn.ReadMsgUDPAddrPort(buf, cmsgBuf)
+ if err != nil {
+ t.Fatalf("ReadMsgUDPAddrPort failed: %v", err)
+ }
+ if cmsgn != 0 {
+ t.Errorf("ReadMsgUDPAddrPort read %d cmsg bytes; want 0", cmsgn)
+ }
+}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Can someone please submit this CL or put a Auto-Submit on it? I have no permission to submit changes. Thanks.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
net: correctly handle non-nil empty cmsg buffer on windows
Fixes #77875.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[release-branch.go1.26] net: correctly handle non-nil empty cmsg buffer on windows
Updates #77875
Fixes #77885
Change-Id: I0ed91be7ed10c04ddea3af55548a8dbf0be5f3a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/750420
Reviewed-by: Quim Muntal <quimm...@gmail.com>
Reviewed-by: Damien Neil <dn...@google.com>
Reviewed-by: David Chase <drc...@google.com>
LUCI-TryBot-Result: Go LUCI <golang...@luci-project-accounts.iam.gserviceaccount.com>
(cherry picked from commit 9e0b5684e1f7166d6427635673001c80218ac9f4)
diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go
index edad656..2ba967f9 100644
--- a/src/internal/poll/fd_windows.go
+++ b/src/internal/poll/fd_windows.go
@@ -159,9 +159,11 @@
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[release-branch.go1.26] net: correctly handle non-nil empty cmsg buffer on windows
Updates #77875
Fixes #77885
Change-Id: I0ed91be7ed10c04ddea3af55548a8dbf0be5f3a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/750420
Reviewed-by: Quim Muntal <quimm...@gmail.com>
Reviewed-by: Damien Neil <dn...@google.com>
Reviewed-by: David Chase <drc...@google.com>
LUCI-TryBot-Result: Go LUCI <golang...@luci-project-accounts.iam.gserviceaccount.com>
(cherry picked from commit 9e0b5684e1f7166d6427635673001c80218ac9f4)
Reviewed-on: https://go-review.googlesource.com/c/go/+/753060
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |