Skip to content

feat: added fuzz #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading