Skip to content

Commit

Permalink
feat: added fuzz (#96)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 28f6b33 commit bc92640
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 0.5.0
* Typos in documentation fixed.
* Added cargo-fuzz for fuzzing.
* Uncovered area in V9 that could cause panic.

# 0.4.9
* Added FlowStartMilliseconds, FlowEndMilliseconds
Expand Down
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
21 changes: 21 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "netflow_parser-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.netflow_parser]
path = ".."

[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
test = false
doc = false
bench = false
3 changes: 3 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```rustup default nightly```

```cargo fuzz run fuzz_target_1```
8 changes: 8 additions & 0 deletions fuzz/fuzz_targets/fuzz_target_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use netflow_parser::NetflowParser;

fuzz_target!(|data: &[u8]| {
NetflowParser::default().parse_bytes(data);
});
4 changes: 3 additions & 1 deletion src/variable_versions/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ pub struct OptionDataField {

impl Template {
fn get_total_size(&self) -> u16 {
self.fields.iter().fold(0, |acc, i| acc + i.field_length)
self.fields
.iter()
.fold(0, |acc, i| acc.saturating_add(i.field_length))
}
}

Expand Down

0 comments on commit bc92640

Please sign in to comment.