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>
This commit is contained in:
parent
2e0774f246
commit
1cf89f5339
@ -160,11 +160,10 @@ retry:
|
|||||||
packet, err := tun.session.ReceivePacket()
|
packet, err := tun.session.ReceivePacket()
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
packetSize := len(packet)
|
n := copy(bufs[0][offset:], packet)
|
||||||
copy(bufs[0][offset:], packet)
|
sizes[0] = n
|
||||||
sizes[0] = packetSize
|
|
||||||
tun.session.ReleaseReceivePacket(packet)
|
tun.session.ReleaseReceivePacket(packet)
|
||||||
tun.rate.update(uint64(packetSize))
|
tun.rate.update(uint64(n))
|
||||||
return 1, nil
|
return 1, nil
|
||||||
case windows.ERROR_NO_MORE_ITEMS:
|
case windows.ERROR_NO_MORE_ITEMS:
|
||||||
if !shouldSpin || uint64(nanotime()-start) >= spinloopDuration {
|
if !shouldSpin || uint64(nanotime()-start) >= spinloopDuration {
|
||||||
|
Loading…
Reference in New Issue
Block a user