Skip to content

Commit

Permalink
add fuzz_for_duration functionality to Fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
R9295 committed Jun 18, 2024
1 parent 51db18e commit bbba3b3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion libafl/src/fuzzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use serde::{de::DeserializeOwned, Serialize};

use crate::{
corpus::{Corpus, CorpusId, HasCurrentCorpusId, HasTestcase, Testcase},
events::{Event, EventConfig, EventFirer, EventProcessor, ProgressReporter},
events::{
CustomBufEventResult, Event, EventConfig, EventFirer, EventProcessor, ProgressReporter,
},
executors::{Executor, ExitKind, HasObservers},
feedbacks::Feedback,
inputs::UsesInput,
Expand Down Expand Up @@ -220,6 +222,27 @@ where
}
}

/// Fuzz for x amount of time.
fn fuzz_for_duration(
&mut self,
stages: &mut ST,
executor: &mut E,
state: &mut Self::State,
manager: &mut EM,
duration: Duration,
) -> Result<(), Error> {
let monitor_timeout = STATS_TIMEOUT_DEFAULT;
let start_time = current_time();
loop {
manager.maybe_report_progress(state, monitor_timeout)?;
self.fuzz_one(stages, executor, state, manager)?;
if current_time().saturating_sub(start_time) >= duration {
break;
}
}
Ok(())
}

/// Fuzz for n iterations.
/// Returns the index of the last fuzzed corpus item.
/// (Note: An iteration represents a complete run of every stage.
Expand Down

0 comments on commit bbba3b3

Please sign in to comment.