Skip to content

Commit 2582d15

Browse files
committed
Fix a crash printing a malformed TCP packet.
Found via cargo-fuzz.
1 parent 6271dc7 commit 2582d15

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/wire/tcp.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,13 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Packet<&'a T> {
729729
try!(write!(f, " urg={}", self.urgent_at()))
730730
}
731731
try!(write!(f, " len={}", self.payload().len()));
732+
733+
let header_len = self.header_len() as usize;
734+
if header_len < field::URGENT.end {
735+
try!(write!(f, " {}", Error::Truncated));
736+
return Ok(())
737+
}
738+
732739
let mut options = self.options();
733740
while options.len() > 0 {
734741
let (next_options, option) =

0 commit comments

Comments
 (0)