net/packet: fix panic on invalid IHL field.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2020-11-10 19:10:11 -08:00
committed by Dave Anderson
parent 22bf48f37c
commit 9ef39af2f2
2 changed files with 29 additions and 1 deletions

View File

@@ -165,6 +165,11 @@ func (q *Parsed) decode4(b []byte) {
q.DstIP4 = IP4(binary.BigEndian.Uint32(b[16:20]))
q.subofs = int((b[0] & 0x0F) << 2)
if q.subofs > q.length {
// next-proto starts beyond end of packet.
q.IPProto = Unknown
return
}
sub := b[q.subofs:]
// We don't care much about IP fragmentation, except insofar as it's