Skip to content

Commit 3f43be8

Browse files
committed
Fix a crash parsing malformed TCP options.
Found via cargo-fuzz.
1 parent 2582d15 commit 3f43be8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/wire/tcp.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ impl<'a> TcpOption<'a> {
514514
}
515515
kind => {
516516
length = *buffer.get(1).ok_or(Error::Truncated)? as usize;
517-
if buffer.len() < length { return Err(Error::Truncated) }
518-
let data = &buffer[2..length];
517+
let data = buffer.get(2..length).ok_or(Error::Truncated)?;
519518
match (kind, length) {
520519
(field::OPT_END, _) |
521520
(field::OPT_NOP, _) =>
@@ -931,6 +930,8 @@ mod test {
931930
Err(Error::Truncated));
932931
assert_eq!(TcpOption::parse(&[0xc, 0x05, 0x01, 0x02]),
933932
Err(Error::Truncated));
933+
assert_eq!(TcpOption::parse(&[0xc, 0x01]),
934+
Err(Error::Truncated));
934935
assert_eq!(TcpOption::parse(&[0x2, 0x02]),
935936
Err(Error::Malformed));
936937
assert_eq!(TcpOption::parse(&[0x3, 0x02]),

0 commit comments

Comments
 (0)