aboutsummaryrefslogtreecommitdiffstats
path: root/tun/tun_windows.go
diff options
context:
space:
mode:
authorJordan Whited <jordan@tailscale.com>2023-11-08 14:06:20 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2023-12-11 16:20:49 +0100
commit1cf89f5339b549236f38ce5fbc40f7bf993d9626 (patch)
tree25e5ebe8cb6f831705ec2efe895638fc19bba443 /tun/tun_windows.go
parentdevice: ratchet up max segment size on android (diff)
downloadwireguard-go-1cf89f5339b549236f38ce5fbc40f7bf993d9626.tar.xz
wireguard-go-1cf89f5339b549236f38ce5fbc40f7bf993d9626.zip
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 <bradfitz@tailscale.com> Signed-off-by: Jordan Whited <jordan@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--tun/tun_windows.go7
1 files changed, 3 insertions, 4 deletions
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 {