diff --git a/afl/src/engines/mod.rs b/afl/src/engines/mod.rs index 2ddbb5df1b..0eb5739a1f 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; @@ -101,7 +104,7 @@ where generator: &mut G, engine: &mut Engine, manager: &mut EM, - in_dir: Vec, + in_dirs: &[PathBuf], ) -> Result<(), AflError> where G: Generator, @@ -110,12 +113,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 8d4a6b937b..1011c7e5a1 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::Corpus; use afl::corpus::InMemoryCorpus; @@ -88,15 +89,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 { @@ -105,18 +106,13 @@ 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); - } - } - - if input != None { - for indir in input.clone().unwrap() { - println!("in: {}", indir); - } + match dictionary { + Some(x) => for file in x { + println!("dic: {:?}", file); + }, + None => (), } // original code @@ -151,16 +147,17 @@ 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"); + match input { + Some(x) => { + for indir in &x { + println!("in: {:?}", indir); + }; + + state + .load_initial_inputs(&mut corpus, &mut generator, &mut engine, &mut mgr, &x) + .expect("Failed to load initial corpus") + }, + None => (), } if corpus.count() < 1 {