quic: fix data race caused by aliased DCID
The initServer function was retaining a reference to a []byte that
aliases a packet buffer, which is subsequently recycled.
Make a copy of the data before retaining it.
Fixes golang/go#63783
Change-Id: I3dbb0cdfd78681014dec97ff9909ff6c7dbf82ba
Reviewed-on: https://go-review.googlesource.com/c/net/+/538615
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/quic/conn_id.go b/internal/quic/conn_id.go
index c236137..91ccaad 100644
--- a/internal/quic/conn_id.go
+++ b/internal/quic/conn_id.go
@@ -97,12 +97,13 @@
}
func (s *connIDState) initServer(c *Conn, dstConnID []byte) error {
+ dstConnID = cloneBytes(dstConnID)
// Client-chosen, transient connection ID received in the first Initial packet.
// The server will not use this as the Source Connection ID of packets it sends,
// but remembers it because it may receive packets sent to this destination.
s.local = append(s.local, connID{
seq: -1,
- cid: cloneBytes(dstConnID),
+ cid: dstConnID,
})
// Server chooses a connection ID, and sends it in the Source Connection ID of