From c617f3a3979ed147221e05a967e2d02e0433ec76 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Fri, 20 Nov 2020 13:28:34 +0100 Subject: [PATCH] libfuzzer clone project --- .gitignore | 4 +-- Cargo.toml | 2 +- fuzzers/libfuzzer/libfuzzer/Cargo.toml | 10 ++++++ fuzzers/libfuzzer/libfuzzer/src/main.rs | 43 +++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 fuzzers/libfuzzer/libfuzzer/Cargo.toml create mode 100644 fuzzers/libfuzzer/libfuzzer/src/main.rs diff --git a/.gitignore b/.gitignore index aaacb75743..9594ae1719 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/target +target Cargo.lock -.vscode \ No newline at end of file +.vscode diff --git a/Cargo.toml b/Cargo.toml index ca7d392d14..855da78253 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ std = [] xxhash-rust = { version = "0.8.0-beta.4", features = ["xxh3"] } # xxh3 hashing for rust hashbrown = "0.9" # A faster hashmap, nostd compatible libc = "0.2" # For (*nix) libc -num = "*" \ No newline at end of file +num = "*" diff --git a/fuzzers/libfuzzer/libfuzzer/Cargo.toml b/fuzzers/libfuzzer/libfuzzer/Cargo.toml new file mode 100644 index 0000000000..8a002251e0 --- /dev/null +++ b/fuzzers/libfuzzer/libfuzzer/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "libfuzzer" +version = "0.1.0" +authors = ["Andrea Fioraldi "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +afl = { path = "../../../" } diff --git a/fuzzers/libfuzzer/libfuzzer/src/main.rs b/fuzzers/libfuzzer/libfuzzer/src/main.rs new file mode 100644 index 0000000000..5351933387 --- /dev/null +++ b/fuzzers/libfuzzer/libfuzzer/src/main.rs @@ -0,0 +1,43 @@ +use std::boxed::Box; + +use afl::corpus::{Corpus, InMemoryCorpus, Testcase}; +use afl::engines::{DefaultEngine, DefaultState, Engine}; +use afl::executors::inmemory::InMemoryExecutor; +use afl::executors::{Executor, ExitKind}; +use afl::inputs::bytes::BytesInput; +use afl::mutators::scheduled::{ + mutation_bitflip, ComposedByMutations, DefaultScheduledMutator, +}; +use afl::stages::mutational::DefaultMutationalStage; +use afl::utils::DefaultRand; + +fn harness(_executor: &dyn Executor, _buf: &[u8]) -> ExitKind { + ExitKind::Ok +} + +pub fn main() { + let rand = DefaultRand::new(0).into(); + + let mut corpus = InMemoryCorpus::::new(&rand); + let testcase = Testcase::new(vec![0; 4]).into(); + corpus.add(testcase); + + let executor = InMemoryExecutor::::new(harness); + let mut state = DefaultState::new(corpus, executor); + + let mut engine = DefaultEngine::new(); + let mut mutator = DefaultScheduledMutator::new(&rand); + mutator.add_mutation(mutation_bitflip); + let stage = DefaultMutationalStage::new(&rand, mutator); + engine.add_stage(Box::new(stage)); + + // + + for i in 0..1000 { + engine + .fuzz_one(&mut state) + .expect(&format!("Error in iter {}", i)); + } + println!("OK"); +} +