1 #![no_main]
2 use libfuzzer_sys::fuzz_target;
3 use smoltcp::wire::{Ieee802154Frame, Ieee802154Repr};
4 
5 fuzz_target!(|data: &[u8]| {
6     if let Ok(frame) = Ieee802154Frame::new_checked(data) {
7         if let Ok(repr) = Ieee802154Repr::parse(frame) {
8             // The buffer len returns only the length required for emitting the header
9             // and does not take into account the length of the payload.
10             let mut buffer = vec![0; repr.buffer_len()];
11 
12             // NOTE: unchecked because the checked version checks if the addressing mode field
13             // is valid or not. The addressing mode field is required for calculating the length of
14             // the header, which is used in `check_len`.
15             let mut frame = Ieee802154Frame::new_unchecked(&mut buffer[..]);
16             repr.emit(&mut frame);
17         }
18     };
19 });
20