Fix panic where slice goes out of bounds because iface.Read returns less than zero (which might happen when the TUN/TAP interface is closed)

This commit is contained in:
Neil Alexander 2019-09-18 14:05:18 +01:00
parent 40204caab6
commit c3016e680c
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -111,7 +111,7 @@ func (r *tunReader) _read() {
recvd := util.ResizeBytes(util.GetBytes(), 65535+tun_ETHER_HEADER_LENGTH)
// Wait for a packet to be delivered to us through the TUN/TAP adapter
n, err := r.tun.iface.Read(recvd)
if n == 0 {
if n <= 0 {
util.PutBytes(recvd)
} else {
r.tun.handlePacketFrom(r, recvd[:n], err)