Skip to content
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

test: Experiment with cargo fuzz #1764

Merged
merged 53 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f8b61bb
test: Experiment with `cargo fuzz`
larseggert Mar 21, 2024
c645903
Fix
larseggert Mar 21, 2024
3835aeb
Fixes
larseggert Mar 22, 2024
f0bdb36
Fixes
larseggert Mar 22, 2024
80d6ecc
Make clippy happy
larseggert Mar 22, 2024
2317193
Merge branch 'main' into test-cargo-fuzz
larseggert Mar 22, 2024
95c57b8
Another clippy fix
larseggert Mar 22, 2024
126df0e
Merge branch 'main' into test-cargo-fuzz
larseggert Mar 22, 2024
c83c676
Fuzz `Frame::decode`
larseggert Mar 23, 2024
a103d0a
Merge remote-tracking branch 'origin/main' into test-cargo-fuzz
larseggert Mar 27, 2024
51c75d9
Rework
larseggert Mar 27, 2024
680a65c
Merge branch 'main' into test-cargo-fuzz
larseggert Mar 27, 2024
09356fe
Fix clippy
larseggert Mar 27, 2024
679c1a0
Try and disable on Windows
larseggert Mar 27, 2024
e72fc33
Retry
larseggert Mar 27, 2024
7f7b29b
Retry
larseggert Mar 27, 2024
de752cb
Try again
larseggert Mar 27, 2024
6344d25
Merge branch 'main' into test-cargo-fuzz
larseggert Mar 28, 2024
01c9b63
Review suggestions
mxinden Apr 3, 2024
5fcbfde
Merge branch 'main' into test-cargo-fuzz
larseggert Apr 3, 2024
fae9e94
Clippy
larseggert Apr 3, 2024
c0a9da1
Update Cargo.toml
larseggert Apr 4, 2024
5ff8b8e
Update neqo-transport/src/packet/mod.rs
larseggert Apr 4, 2024
5a79163
Rename directory to `fuzz`
larseggert Apr 4, 2024
23b09ec
`lazy_static` -> `OnceLock`
larseggert Apr 4, 2024
ecceb98
Merge branch 'main' into test-cargo-fuzz
larseggert Apr 4, 2024
f0783df
* Add ability to save items to fuzzing corpus via
larseggert Apr 5, 2024
e7beafb
Merge branch 'main' into test-cargo-fuzz
larseggert Apr 5, 2024
d8ce45b
Clippy
larseggert Apr 5, 2024
f7dae6f
`DefaultHasher` is not in `std::hash` yet in Rust 1.74
larseggert Apr 5, 2024
c9d7d8a
Merge branch 'main' into test-cargo-fuzz
larseggert Apr 11, 2024
a826a07
Add two more fuzzers
larseggert Apr 11, 2024
b5f35b2
Tweaks
larseggert Apr 11, 2024
1ab41f5
Don't check coverage for fuzzing code
larseggert Apr 11, 2024
590b041
Update neqo-common/src/fuzz.rs
larseggert Apr 16, 2024
6da296f
Update neqo-transport/src/connection/mod.rs
larseggert Apr 16, 2024
31ce2ff
Update neqo-transport/src/connection/mod.rs
larseggert Apr 16, 2024
ae3ed74
Update neqo-crypto/src/p11.rs
larseggert Apr 16, 2024
dc977da
Fixups
larseggert Apr 16, 2024
7c43a64
More fixups
larseggert Apr 16, 2024
aab7076
Merge branch 'main' into test-cargo-fuzz
larseggert Apr 16, 2024
0979fba
Remove `fuzz/src/lib.rs` now that #1830 is merged
larseggert Apr 16, 2024
dc19d82
Merge branch 'main' into test-cargo-fuzz
larseggert Apr 16, 2024
c8d55e4
Merge branch 'main' into test-cargo-fuzz
larseggert Apr 16, 2024
a2eedfc
Merge branch 'main' into test-cargo-fuzz
larseggert Apr 17, 2024
d70f1f1
Fix merge
larseggert Apr 17, 2024
2126526
Create corpus directory if it does not exist
larseggert Apr 17, 2024
3766868
Use a predictable sequence of bytes for `disable-random` instead of j…
larseggert Apr 17, 2024
09dbf15
Update neqo-common/src/lib.rs
larseggert Apr 18, 2024
e5159e5
Use thread-local instead of atomic
larseggert Apr 18, 2024
9a78b7f
Only write generated packets, and only ones without test frames
larseggert Apr 18, 2024
5d55f1f
Build a corpus for `client_initial` and `server_initial` fuzz targets
larseggert Apr 18, 2024
ed79956
Cleanup
larseggert Apr 18, 2024
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"fuzz",
larseggert marked this conversation as resolved.
Show resolved Hide resolved
"neqo-bin",
"neqo-common",
"neqo-crypto",
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
37 changes: 37 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "neqo-fuzz"
authors.workspace = true
homepage.workspace = true
repository.workspace = true
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true

[package.metadata]
cargo-fuzz = true

[dependencies]
neqo-common = { path = "../neqo-common" }
neqo-crypto = { path = "../neqo-crypto" }
neqo-transport = { path = "../neqo-transport", features = ["fuzzing"] }

[target.'cfg(not(windows))'.dependencies]
libfuzzer-sys = { version = "0.4" }

[lints]
workspace = true

[[bin]]
name = "packet"
path = "fuzz_targets/packet.rs"
test = false
doc = false
bench = false

[[bin]]
name = "frame"
path = "fuzz_targets/frame.rs"
test = false
doc = false
bench = false
17 changes: 17 additions & 0 deletions fuzz/fuzz_targets/frame.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![cfg_attr(not(windows), no_main)]

#[cfg(not(windows))]
larseggert marked this conversation as resolved.
Show resolved Hide resolved
use libfuzzer_sys::fuzz_target;

#[cfg(not(windows))]
fuzz_target!(|data: &[u8]| {
use neqo_common::Decoder;
use neqo_transport::frame::Frame;

// Run the fuzzer
let mut decoder = Decoder::new(data);
let _ = Frame::decode(&mut decoder);
});

#[cfg(windows)]
fn main() {}
29 changes: 29 additions & 0 deletions fuzz/fuzz_targets/packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![cfg_attr(not(windows), no_main)]

#[cfg(not(windows))]
use libfuzzer_sys::fuzz_target;

#[cfg(not(windows))]
fuzz_target!(|data: &[u8]| {
use std::sync::Once;

use neqo_transport::{packet::PublicPacket, RandomConnectionIdGenerator};

static INIT: Once = Once::new();
static mut DECODER: Option<neqo_transport::RandomConnectionIdGenerator> = None;

// Initialize things
unsafe {
INIT.call_once(|| {
neqo_crypto::init();
larseggert marked this conversation as resolved.
Show resolved Hide resolved
DECODER = Some(RandomConnectionIdGenerator::new(20));
larseggert marked this conversation as resolved.
Show resolved Hide resolved
});
}
let decoder = unsafe { DECODER.as_ref().unwrap() };

// Run the fuzzer
let _ = PublicPacket::decode(data, decoder);
});

#[cfg(windows)]
fn main() {}
1 change: 1 addition & 0 deletions neqo-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test-fixture = { path = "../test-fixture" }
[features]
bench = []
disable-encryption = ["neqo-crypto/disable-encryption"]
fuzzing = []

[lib]
# See https://github.com/bheisler/criterion.rs/blob/master/book/src/faq.md#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
Expand Down
6 changes: 6 additions & 0 deletions neqo-transport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ mod connection;
mod crypto;
mod events;
mod fc;
#[cfg(feature = "fuzzing")]
pub mod frame;
#[cfg(not(feature = "fuzzing"))]
mod frame;
mod pace;
#[cfg(feature = "fuzzing")]
pub mod packet;
#[cfg(not(feature = "fuzzing"))]
mod packet;
mod path;
mod qlog;
Expand Down
1 change: 1 addition & 0 deletions neqo-transport/src/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ impl<'a> PublicPacket<'a> {
}

#[must_use]
#[allow(clippy::len_without_is_empty)]
larseggert marked this conversation as resolved.
Show resolved Hide resolved
pub fn len(&self) -> usize {
self.data.len()
}
Expand Down