]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: fix Device.Read() buf length assumption on Windows
authorJordan Whited <jordan@tailscale.com>
Wed, 8 Nov 2023 22:06:20 +0000 (14:06 -0800)
committerJason A. Donenfeld <Jason@zx2c4.com>
Mon, 11 Dec 2023 15:20:49 +0000 (16:20 +0100)
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 <bradfitz@tailscale.com>
Signed-off-by: Jordan Whited <jordan@tailscale.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
tun/tun_windows.go

index 34f29805da1dc9431e3691ddb1ddbdadd7c3fabb..2af8e3e922b1fa6c7e2b11c7850790d995124cbc 100644 (file)
@@ -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 {