From 6480b2c2a0a9263d6762c0b8530c5803fcb7b2a8 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 2 Feb 2022 14:59:53 -0800 Subject: [PATCH] Adding fuzzers for unsafe code. --- fuzz/Cargo.toml | 31 +++++++++++++++++++++++++++++++ fuzz/fuzz_targets/fuzz_next.rs | 10 ++++++++++ fuzz/fuzz_targets/fuzz_quote.rs | 9 +++++++++ 3 files changed, 50 insertions(+) create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/fuzz_targets/fuzz_next.rs create mode 100644 fuzz/fuzz_targets/fuzz_quote.rs diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..1533360 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "shlex-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.shlex] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "fuzz_next" +path = "fuzz_targets/fuzz_next.rs" +test = false +doc = false + +[[bin]] +name = "fuzz_quote" +path = "fuzz_targets/fuzz_quote.rs" +test = false +doc = false diff --git a/fuzz/fuzz_targets/fuzz_next.rs b/fuzz/fuzz_targets/fuzz_next.rs new file mode 100644 index 0000000..64b7a2a --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_next.rs @@ -0,0 +1,10 @@ +#![no_main] +#[macro_use] extern crate libfuzzer_sys; +use shlex::Shlex; + +fuzz_target!(|data: &[u8]| { + if let Ok(s) = std::str::from_utf8(data) { + let mut sh = Shlex::new(s); + while let Some(word) = sh.next() {} + } +}); diff --git a/fuzz/fuzz_targets/fuzz_quote.rs b/fuzz/fuzz_targets/fuzz_quote.rs new file mode 100644 index 0000000..2178dde --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_quote.rs @@ -0,0 +1,9 @@ +#![no_main] +#[macro_use] extern crate libfuzzer_sys; +use shlex::quote; + +fuzz_target!(|data: &[u8]| { + if let Ok(s) = std::str::from_utf8(data) { + quote(s); + } +});