Skip to content

Commit bc92640

Browse files
mikemiles-devMichael Mileusnichmikemiles-dev
authored
feat: added fuzz (#96)
* feat: fuzzing, bug: fixed v9 field counting --------- Co-authored-by: Michael Mileusnich <mmileusnich@gmail.com> Co-authored-by: mikemiles-dev <michaelmileusnich@Michaels-MacBook-Air-2.local>
1 parent 28f6b33 commit bc92640

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

RELEASES.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# 0.5.0
22
* Typos in documentation fixed.
3+
* Added cargo-fuzz for fuzzing.
4+
* Uncovered area in V9 that could cause panic.
35

46
# 0.4.9
57
* Added FlowStartMilliseconds, FlowEndMilliseconds

fuzz/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
corpus
3+
artifacts
4+
coverage

fuzz/Cargo.toml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "netflow_parser-fuzz"
3+
version = "0.0.0"
4+
publish = false
5+
edition = "2021"
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
libfuzzer-sys = "0.4"
12+
13+
[dependencies.netflow_parser]
14+
path = ".."
15+
16+
[[bin]]
17+
name = "fuzz_target_1"
18+
path = "fuzz_targets/fuzz_target_1.rs"
19+
test = false
20+
doc = false
21+
bench = false

fuzz/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```rustup default nightly```
2+
3+
```cargo fuzz run fuzz_target_1```

fuzz/fuzz_targets/fuzz_target_1.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![no_main]
2+
3+
use libfuzzer_sys::fuzz_target;
4+
use netflow_parser::NetflowParser;
5+
6+
fuzz_target!(|data: &[u8]| {
7+
NetflowParser::default().parse_bytes(data);
8+
});

src/variable_versions/v9.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ pub struct OptionDataField {
285285

286286
impl Template {
287287
fn get_total_size(&self) -> u16 {
288-
self.fields.iter().fold(0, |acc, i| acc + i.field_length)
288+
self.fields
289+
.iter()
290+
.fold(0, |acc, i| acc.saturating_add(i.field_length))
289291
}
290292
}
291293

0 commit comments

Comments
 (0)