move cutting of packets with a length to the packet handler map

This commit is contained in:
Marten Seemann
2018-12-26 22:01:27 +07:00
parent 767dbdd545
commit 6ce7a204fc
4 changed files with 33 additions and 54 deletions

View File

@@ -173,6 +173,14 @@ func (h *packetHandlerMap) handlePacket(
return fmt.Errorf("error parsing header: %s", err)
}
if hdr.IsLongHeader {
if protocol.ByteCount(r.Len()) < hdr.Length {
return fmt.Errorf("packet length (%d bytes) is smaller than the expected length (%d bytes)", len(data)-int(hdr.ParsedLen()), hdr.Length)
}
data = data[:int(hdr.ParsedLen()+hdr.Length)]
// TODO(#1312): implement parsing of compound packets
}
p := &receivedPacket{
remoteAddr: addr,
hdr: hdr,