diff --git a/afl/src/engines/mod.rs b/afl/src/engines/mod.rs index 138b87700f..fc0d94bb32 100644 --- a/afl/src/engines/mod.rs +++ b/afl/src/engines/mod.rs @@ -3,7 +3,10 @@ use core::fmt::Debug; use core::marker::PhantomData; use serde::{Deserialize, Serialize}; -use std::{fs, path::Path}; +use std::{ + fs, + path::{Path, PathBuf}, +}; use crate::corpus::{Corpus, Testcase}; use crate::events::EventManager; @@ -83,7 +86,7 @@ where if attr.is_file() { println!("Load file {:?}", &path); - let bytes = std::fs::read(path)?; + let bytes = std::fs::read(&path)?; let input = BytesInput::new(bytes); let fitness = self.evaluate_input(&input, engine.executor_mut())?; if self.add_if_interesting(corpus, input, fitness)?.is_none() { @@ -103,7 +106,7 @@ where generator: &mut G, engine: &mut Engine, manager: &mut EM, - in_dir: Vec, + in_dirs: &[PathBuf], ) -> Result<(), AflError> where G: Generator, @@ -112,12 +115,12 @@ where ET: ExecutorsTuple, EM: EventManager, { - for directory in &in_dir { - self.load_from_directory(corpus, generator, engine, manager, Path::new(directory))?; + for in_dir in in_dirs { + self.load_from_directory(corpus, generator, engine, manager, in_dir)?; } manager.log( 0, - format!("Loaded {} initial testcases", in_dir.len()), // get corpus count + format!("Loaded {} initial testcases", in_dirs.len()), // get corpus count )?; manager.process(self, corpus)?; Ok(()) diff --git a/fuzzers/libfuzzer/src/lib.rs b/fuzzers/libfuzzer/src/lib.rs index dd56dc5c24..25767a5c48 100644 --- a/fuzzers/libfuzzer/src/lib.rs +++ b/fuzzers/libfuzzer/src/lib.rs @@ -6,6 +6,7 @@ extern crate alloc; use clap::{App, Arg}; use std::env; +use std::path::PathBuf; use afl::corpus::InMemoryCorpus; use afl::engines::Engine; @@ -87,15 +88,15 @@ pub extern "C" fn afl_libfuzzer_main() { env::current_dir().unwrap().to_string_lossy().to_string() }; - let mut dictionary: Option> = None; + let mut dictionary: Option> = None; if matches.is_present("dictionary") { - dictionary = Some(values_t!(matches, "dictionary", String).unwrap_or_else(|e| e.exit())); + dictionary = Some(values_t!(matches, "dictionary", PathBuf).unwrap_or_else(|e| e.exit())); } - let mut input: Option> = None; + let mut input: Option> = None; if matches.is_present("workdir") { - input = Some(values_t!(matches, "workdir", String).unwrap_or_else(|e| e.exit())); + input = Some(values_t!(matches, "workdir", PathBuf).unwrap_or_else(|e| e.exit())); } if dictionary != None || input != None { @@ -104,18 +105,24 @@ pub extern "C" fn afl_libfuzzer_main() { // debug prints - println!("workdir: {}", workdir); + println!("workdir: {:?}", workdir); - if dictionary != None { - for file in dictionary.unwrap() { - println!("dic: {}", file); + match dictionary { + Some(ref x) => { + for file in x { + println!("dic: {:?}", file); + } } + None => (), } - if input != None { - for indir in input.clone().unwrap() { - println!("in: {}", indir); + match input { + Some(ref x) => { + for indir in x { + println!("in: {:?}", indir); + } } + None => (), } // original code @@ -149,18 +156,11 @@ pub extern "C" fn afl_libfuzzer_main() { // } // } - if input != None { - state - .load_initial_inputs( - &mut corpus, - &mut generator, - &mut engine, - &mut mgr, - input.unwrap(), - ) - .expect("Failed to load initial corpus"); - } else { - state + match input { + Some(x) => state + .load_initial_inputs(&mut corpus, &mut generator, &mut engine, &mut mgr, &x) + .expect("Failed to load initial corpus"), + None => state .generate_initial_inputs( &mut rand, &mut corpus, @@ -169,7 +169,7 @@ pub extern "C" fn afl_libfuzzer_main() { &mut mgr, 4, ) - .expect("Failed to load initial inputs"); + .expect("Failed to load initial inputs"), } let mut mutator = HavocBytesMutator::new_default();