From 56625f1475adcdd5cb2f16ae5748894a9a12930d Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Sun, 3 Dec 2023 10:12:55 +0000 Subject: [PATCH] Error out on bad checksums --- src/dhcp.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dhcp.rs b/src/dhcp.rs index 3a64b9d..7a45ec3 100644 --- a/src/dhcp.rs +++ b/src/dhcp.rs @@ -15,6 +15,7 @@ pub enum Error { MissingCookie, InvalidHlen, BufferOverflow, + InvalidPacket, } /// @@ -1349,10 +1350,14 @@ pub mod raw_ip { Err(Error::DataUnderflow)?; } - let checksum = Self::checksum(&packet[..len]); // TODO: Error if invalid + let checksum = Self::checksum(&packet[..len]); trace!("IP header decoded, total_size={}, src={}, dst={}, hlen={}, size={}, checksum={}, ours={}", packet.len(), hdr.src, hdr.dst, hdr.hlen, hdr.len, hdr.sum, checksum); + if checksum != hdr.sum { + Err(Error::InvalidPacket)?; + } + let packet = &packet[..len]; let hdr_len = hdr.hlen as usize; if packet.len() < hdr_len { @@ -1487,6 +1492,10 @@ pub mod raw_ip { checksum ); + if checksum != hdr.sum { + Err(Error::InvalidPacket)?; + } + let packet = &packet[..len]; let payload_data = &packet[Self::SIZE..];