From d16fd07bebe3a8d36fe33ac56f6bead75435864f Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Mon, 15 Feb 2021 12:19:58 +0100 Subject: [PATCH] save ondisk --- .gitignore | 4 +++- afl/src/corpus/ondisk.rs | 1 + afl/src/corpus/testcase.rs | 16 ++++++++++++++++ fuzzers/libfuzzer_libpng/test.sh | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9ea899b9c0..0c466bba6e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,11 @@ Cargo.lock *.dll *.exe +crashes + callgrind.out.* perf.data perf.data.old .vscode -test.dict \ No newline at end of file +test.dict diff --git a/afl/src/corpus/ondisk.rs b/afl/src/corpus/ondisk.rs index e1fb1e57a1..29ee265344 100644 --- a/afl/src/corpus/ondisk.rs +++ b/afl/src/corpus/ondisk.rs @@ -59,6 +59,7 @@ where } _ => {} } + entry.store_input().expect("Could not save testcase to disk".into()); self.entries.push(RefCell::new(entry)); self.entries.len() - 1 } diff --git a/afl/src/corpus/testcase.rs b/afl/src/corpus/testcase.rs index f605826683..3e1cbb7954 100644 --- a/afl/src/corpus/testcase.rs +++ b/afl/src/corpus/testcase.rs @@ -41,6 +41,22 @@ where Ok(self.input.as_ref().unwrap()) } + /// Store the input to disk if possible + pub fn store_input(&mut self) -> Result { + let fname; + match self.filename() { + Some(f) => { fname = f.clone(); }, + None => { return Ok(false); } + }; + match self.input_mut() { + None => Ok(false), + Some(i) => { + i.to_file(fname)?; + Ok(true) + } + } + } + /// Get the input, if any #[inline] pub fn input(&self) -> &Option { diff --git a/fuzzers/libfuzzer_libpng/test.sh b/fuzzers/libfuzzer_libpng/test.sh index 5f5b2b7176..e852e449e1 100755 --- a/fuzzers/libfuzzer_libpng/test.sh +++ b/fuzzers/libfuzzer_libpng/test.sh @@ -1,5 +1,7 @@ #!/bin/sh +mkdir -p ./crashes + cargo build --release || exit 1 cp ../../target/release/libfuzzer ./.libfuzzer_test.elf