From: Jordan Whited Date: Wed, 8 Nov 2023 22:06:20 +0000 (-0800) Subject: tun: fix Device.Read() buf length assumption on Windows X-Git-Tag: 0.0.20250515~19 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=1cf89f5339b549236f38ce5fbc40f7bf993d9626;p=thirdparty%2Fwireguard-go.git tun: fix Device.Read() buf length assumption on Windows The length of a packet read from the underlying TUN device may exceed the length of a supplied buffer when MTU exceeds device.MaxMessageSize. Reviewed-by: Brad Fitzpatrick Signed-off-by: Jordan Whited Signed-off-by: Jason A. Donenfeld --- diff --git a/tun/tun_windows.go b/tun/tun_windows.go index 34f2980..2af8e3e 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -160,11 +160,10 @@ retry: packet, err := tun.session.ReceivePacket() switch err { case nil: - packetSize := len(packet) - copy(bufs[0][offset:], packet) - sizes[0] = packetSize + n := copy(bufs[0][offset:], packet) + sizes[0] = n tun.session.ReleaseReceivePacket(packet) - tun.rate.update(uint64(packetSize)) + tun.rate.update(uint64(n)) return 1, nil case windows.ERROR_NO_MORE_ITEMS: if !shouldSpin || uint64(nanotime()-start) >= spinloopDuration {