Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fuzzer #842

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/sixlowpan_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fuzz_target!(|fuzz: SixlowpanPacketFuzzer| {
&iphc_repr.dst_addr,
frame.payload().len(),
|b| b.copy_from_slice(frame.payload()),
&ChecksumCapabilities::ignored(),
);
}
}
Expand Down Expand Up @@ -181,7 +182,7 @@ fuzz_target!(|fuzz: SixlowpanPacketFuzzer| {
if let Ok(frame) = Ipv6RoutingHeader::new_checked(payload) {
if let Ok(repr) = Ipv6RoutingRepr::parse(&frame) {
let mut buffer = vec![0; repr.buffer_len()];
let mut packet = Ipv6RoutingHeader::new(&mut buffer[..]);
let mut packet = Ipv6RoutingHeader::new_unchecked(&mut buffer[..]);
repr.emit(&mut packet);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/wire/ipv6routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Header<T> {
Type::Rpl => {
// Retain the higher order 4 bits of the padding field
data[field::PAD] &= 0xF0;
data[6] = 0;
data[7] = 0;
data[4] = 0;
data[5] = 0;
}

_ => panic!("Unrecognized routing type when clearing reserved fields."),
Expand Down
29 changes: 22 additions & 7 deletions src/wire/sixlowpan/nhc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<T: AsRef<[u8]>> ExtHeaderPacket<T> {
return Err(Error);
}

let mut len = 1;
let mut len = 2;
len += self.next_header_size();

if len <= buffer.len() {
Expand Down Expand Up @@ -190,11 +190,7 @@ impl<T: AsRef<[u8]>> ExtHeaderPacket<T> {
NextHeader::Compressed
} else {
// The full 8 bits for Next Header are carried in-line.
let start = 1;

let data = self.buffer.as_ref();
let nh = data[start];
NextHeader::Uncompressed(IpProtocol::from(nh))
NextHeader::Uncompressed(IpProtocol::from(self.buffer.as_ref()[1]))
}
}

Expand Down Expand Up @@ -803,13 +799,32 @@ mod test {
use super::*;

#[test]
fn ext_header_nhc_fields() {
fn ext_header_nh_inlined() {
let bytes = [0xe2, 0x3a, 0x6, 0x3, 0x0, 0xff, 0x0, 0x0, 0x0];

let packet = ExtHeaderPacket::new_checked(&bytes[..]).unwrap();
assert_eq!(packet.next_header_size(), 1);
assert_eq!(packet.length(), 6);
assert_eq!(packet.dispatch_field(), DISPATCH_EXT_HEADER);
assert_eq!(packet.extension_header_id(), ExtHeaderId::RoutingHeader);
assert_eq!(
packet.next_header(),
NextHeader::Uncompressed(IpProtocol::Icmpv6)
);

assert_eq!(packet.payload(), [0x03, 0x00, 0xff, 0x00, 0x00, 0x00]);
}

#[test]
fn ext_header_nh_elided() {
let bytes = [0xe3, 0x06, 0x03, 0x00, 0xff, 0x00, 0x00, 0x00];

let packet = ExtHeaderPacket::new_checked(&bytes[..]).unwrap();
assert_eq!(packet.next_header_size(), 0);
assert_eq!(packet.length(), 6);
assert_eq!(packet.dispatch_field(), DISPATCH_EXT_HEADER);
assert_eq!(packet.extension_header_id(), ExtHeaderId::RoutingHeader);
assert_eq!(packet.next_header(), NextHeader::Compressed);

assert_eq!(packet.payload(), [0x03, 0x00, 0xff, 0x00, 0x00, 0x00]);
}
Expand Down
Loading