Skip to content

Commit

Permalink
Error out on bad checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Dec 3, 2023
1 parent 1055e3e commit 56625f1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Error {
MissingCookie,
InvalidHlen,
BufferOverflow,
InvalidPacket,
}

///
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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..];
Expand Down

0 comments on commit 56625f1

Please sign in to comment.