sixlowpan_iphc_header.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #![no_main]
  2. use libfuzzer_sys::fuzz_target;
  3. use smoltcp::wire::{Ieee802154Address, SixlowpanIphcPacket, SixlowpanIphcRepr};
  4. #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, arbitrary::Arbitrary)]
  5. pub enum AddressFuzzer {
  6. Absent,
  7. Short([u8; 2]),
  8. Extended([u8; 8]),
  9. }
  10. impl From<AddressFuzzer> for Ieee802154Address {
  11. fn from(val: AddressFuzzer) -> Self {
  12. match val {
  13. AddressFuzzer::Absent => Ieee802154Address::Absent,
  14. AddressFuzzer::Short(b) => Ieee802154Address::Short(b),
  15. AddressFuzzer::Extended(b) => Ieee802154Address::Extended(b),
  16. }
  17. }
  18. }
  19. #[derive(Debug, arbitrary::Arbitrary)]
  20. struct SixlowpanIphcPacketFuzzer<'a> {
  21. data: &'a [u8],
  22. ll_src_addr: Option<AddressFuzzer>,
  23. ll_dst_addr: Option<AddressFuzzer>,
  24. }
  25. fuzz_target!(|fuzz: SixlowpanIphcPacketFuzzer| {
  26. if let Ok(ref frame) = SixlowpanIphcPacket::new_checked(fuzz.data) {
  27. if let Ok(repr) = SixlowpanIphcRepr::parse(
  28. frame,
  29. fuzz.ll_src_addr.map(Into::into),
  30. fuzz.ll_dst_addr.map(Into::into),
  31. ) {
  32. let mut buffer = vec![0; repr.buffer_len()];
  33. let mut frame = SixlowpanIphcPacket::new_unchecked(&mut buffer[..]);
  34. repr.emit(&mut frame);
  35. }
  36. };
  37. });