Skip to content

Commit

Permalink
Fix a crash parsing a truncated TCP packet with options.
Browse files Browse the repository at this point in the history
Found via cargo-fuzz.
  • Loading branch information
whitequark committed Jun 24, 2017
1 parent 3f43be8 commit ed2c376
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/wire/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ impl<T: AsRef<[u8]>> Packet<T> {
if len < field::URGENT.end {
Err(Error::Truncated)
} else {
Ok(())
let header_len = self.header_len() as usize;
if len < header_len {
Err(Error::Truncated)
} else {
Ok(())
}
}
}

Expand Down Expand Up @@ -862,6 +867,12 @@ mod test {
assert_eq!(&packet.into_inner()[..], &PACKET_BYTES[..]);
}

#[test]
fn test_truncated() {
let packet = Packet::new(&PACKET_BYTES[..23]);
assert_eq!(packet.check_len(), Err(Error::Truncated));
}

static SYN_PACKET_BYTES: [u8; 24] =
[0xbf, 0x00, 0x00, 0x50,
0x01, 0x23, 0x45, 0x67,
Expand Down

0 comments on commit ed2c376

Please sign in to comment.