Skip to content

Commit 898eeb2

Browse files
committed
tests/fuzz: refactor imports and improve readability
1 parent 5351b66 commit 898eeb2

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
#![no_main]
2-
use libfuzzer_sys::fuzz_target;
3-
use bytes::Bytes;
2+
use bgpkit_parser::models::{Afi, AsnLength, Safi};
43
use bgpkit_parser::parser::bgp::attributes::parse_attributes;
5-
use bgpkit_parser::models::{AsnLength, Afi, Safi};
4+
use bytes::Bytes;
5+
use libfuzzer_sys::fuzz_target;
66

77
fuzz_target!(|data: &[u8]| {
8-
let mut bytes = Bytes::copy_from_slice(data);
8+
let bytes = Bytes::copy_from_slice(data);
99
// Try without AFI/SAFI context
1010
let _ = parse_attributes(bytes.clone(), &AsnLength::Bits16, false, None, None, None);
1111
// Try with AFI/SAFI contexts
12-
let _ = parse_attributes(bytes.clone(), &AsnLength::Bits32, true, Some(&Afi::Ipv4), Some(&Safi::Unicast), None);
13-
let _ = parse_attributes(bytes, &AsnLength::Bits32, true, Some(&Afi::Ipv6), Some(&Safi::Unicast), None);
12+
let _ = parse_attributes(
13+
bytes.clone(),
14+
&AsnLength::Bits32,
15+
true,
16+
Some(Afi::Ipv4),
17+
Some(Safi::Unicast),
18+
None,
19+
);
20+
let _ = parse_attributes(
21+
bytes,
22+
&AsnLength::Bits32,
23+
true,
24+
Some(Afi::Ipv6),
25+
Some(Safi::Unicast),
26+
None,
27+
);
1428
});

tests/fuzz/fuzz_targets/fuzz_bmp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![no_main]
2-
use libfuzzer_sys::fuzz_target;
3-
use bytes::Bytes;
42
use bgpkit_parser::parser::bmp::{parse_bmp_msg, parse_openbmp_header};
3+
use bytes::Bytes;
4+
use libfuzzer_sys::fuzz_target;
55

66
fuzz_target!(|data: &[u8]| {
7-
let mut bytes = Bytes::copy_from_slice(data);
7+
let bytes = Bytes::copy_from_slice(data);
88
// Try BMP common message parsing directly
99
let _ = parse_bmp_msg(&mut bytes.clone());
1010

0 commit comments

Comments
 (0)