From 90be5436cb8780acd4c8d73a8ce9fc8e33b7b437 Mon Sep 17 00:00:00 2001 From: Marc Greisen Date: Wed, 18 Oct 2023 16:52:09 -0700 Subject: [PATCH] Add fuzzer for coverage allowlist parse function (#3580) --- src/agent/coverage/fuzz/Cargo.lock | 31 +++++++++++++++++++ src/agent/coverage/fuzz/Cargo.toml | 7 +++++ .../fuzz_target_allowlist_parse.rs | 12 +++++++ 3 files changed, 50 insertions(+) create mode 100644 src/agent/coverage/fuzz/fuzz_targets/fuzz_target_allowlist_parse.rs diff --git a/src/agent/coverage/fuzz/Cargo.lock b/src/agent/coverage/fuzz/Cargo.lock index 6096b84473..bbad571079 100644 --- a/src/agent/coverage/fuzz/Cargo.lock +++ b/src/agent/coverage/fuzz/Cargo.lock @@ -145,6 +145,7 @@ dependencies = [ "log", "nix", "pete", + "process_control", "procfs", "regex", "symbolic", @@ -805,6 +806,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "process_control" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e056a69288d0a211f4c74c48391c6eb86e714fdcb9dc58a9f34302da9c20bf" +dependencies = [ + "libc", + "signal-hook", + "windows-sys 0.48.0", +] + [[package]] name = "procfs" version = "0.15.1" @@ -1012,6 +1024,25 @@ dependencies = [ "serde", ] +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "siphasher" version = "0.3.10" diff --git a/src/agent/coverage/fuzz/Cargo.toml b/src/agent/coverage/fuzz/Cargo.toml index 6f23f1b7a0..eef71b5fad 100644 --- a/src/agent/coverage/fuzz/Cargo.toml +++ b/src/agent/coverage/fuzz/Cargo.toml @@ -28,3 +28,10 @@ name = "fuzz_target_record_coverage" path = "fuzz_targets/fuzz_target_record_coverage.rs" test = false doc = false + +[[bin]] +name = "fuzz_target_allowlist_parse" +path = "fuzz_targets/fuzz_target_allowlist_parse.rs" +test = false +doc = false + diff --git a/src/agent/coverage/fuzz/fuzz_targets/fuzz_target_allowlist_parse.rs b/src/agent/coverage/fuzz/fuzz_targets/fuzz_target_allowlist_parse.rs new file mode 100644 index 0000000000..dd27a8b313 --- /dev/null +++ b/src/agent/coverage/fuzz/fuzz_targets/fuzz_target_allowlist_parse.rs @@ -0,0 +1,12 @@ +#![no_main] + +use libfuzzer_sys::fuzz_target; +use coverage::allowlist::AllowList; + +fuzz_target!(|data: &[u8]| { + // fuzzed code goes here + if let Ok(s) = std::str::from_utf8(data) + { + let _ = AllowList::parse(s); + } +});