Skip to content

Commit 0fdfa1d

Browse files
wtdcodetokatoka
andauthored
Add back executions to Testcase (#3115)
* Add back executions to Testcase * Small clippy --------- Co-authored-by: Dongjia "toka" Zhang <[email protected]>
1 parent c99371f commit 0fdfa1d

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-0
lines changed

libafl/src/corpus/inmemory_ondisk.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ impl<I> InMemoryOnDiskCorpus<I> {
407407
let ondisk_meta = OnDiskMetadata {
408408
metadata: testcase.metadata_map(),
409409
exec_time: testcase.exec_time(),
410+
executions: testcase.executions(),
410411
};
411412

412413
let mut tmpfile = File::create(&tmpfile_path)?;

libafl/src/corpus/ondisk.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub struct OnDiskMetadata<'a> {
4343
pub metadata: &'a SerdeAnyMap,
4444
/// The exec time for this [`Testcase`]
4545
pub exec_time: &'a Option<Duration>,
46+
/// The executions of this [`Testcase`]
47+
pub executions: &'a u64,
4648
}
4749

4850
/// A corpus able to store [`Testcase`]s to disk, and load them from disk, when they are being used.

libafl/src/corpus/testcase.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ pub struct Testcase<I> {
5050
cached_len: Option<usize>,
5151
/// Number of fuzzing iterations of this particular input updated in `perform_mutational`
5252
scheduled_count: usize,
53+
/// Number of executions done at discovery time
54+
executions: u64,
5355
/// Parent [`CorpusId`], if known
5456
parent_id: Option<CorpusId>,
5557
/// If the testcase is "disabled"
@@ -145,6 +147,24 @@ impl<I> Testcase<I> {
145147
&mut self.metadata_path
146148
}
147149

150+
/// Get the executions
151+
#[inline]
152+
pub fn executions(&self) -> &u64 {
153+
&self.executions
154+
}
155+
156+
/// Get the executions (mutable)
157+
#[inline]
158+
pub fn executions_mut(&mut self) -> &mut u64 {
159+
&mut self.executions
160+
}
161+
162+
/// Set the executions
163+
#[inline]
164+
pub fn set_executions(&mut self, executions: u64) {
165+
self.executions = executions;
166+
}
167+
148168
/// Get the execution time of the testcase
149169
#[inline]
150170
pub fn exec_time(&self) -> &Option<Duration> {
@@ -228,6 +248,7 @@ impl<I> Testcase<I> {
228248
metadata_path: None,
229249
exec_time: None,
230250
cached_len: None,
251+
executions: 0,
231252
scheduled_count: 0,
232253
parent_id: None,
233254
disabled: false,
@@ -252,6 +273,7 @@ impl<I> Testcase<I> {
252273
metadata_path: None,
253274
exec_time: None,
254275
cached_len: None,
276+
executions: 0,
255277
scheduled_count: 0,
256278
parent_id: Some(parent_id),
257279
disabled: false,
@@ -278,6 +300,7 @@ impl<I> Testcase<I> {
278300
metadata_path: None,
279301
exec_time: None,
280302
cached_len: None,
303+
executions: 0,
281304
scheduled_count: 0,
282305
parent_id: None,
283306
disabled: false,
@@ -333,6 +356,7 @@ impl<I> Default for Testcase<I> {
333356
#[cfg(feature = "std")]
334357
metadata_path: None,
335358
disabled: false,
359+
executions: 0,
336360
objectives_found: 0,
337361
#[cfg(feature = "track_hit_feedbacks")]
338362
hit_feedbacks: Vec::new(),

libafl/src/executors/inprocess/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ pub fn run_observers_and_save_state<E, EM, I, OF, S, Z>(
345345

346346
if is_solution {
347347
let mut new_testcase = Testcase::from(input.clone());
348+
new_testcase.set_executions(*state.executions());
348349
new_testcase.add_metadata(exitkind);
349350
new_testcase.set_parent_id_optional(*state.corpus().current());
350351

libafl/src/fuzzer/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ where
360360
OT: ObserversTuple<I, S> + Serialize,
361361
S: HasCorpus<I>
362362
+ MaybeHasClientPerfMonitor
363+
+ HasExecutions
363364
+ HasCurrentTestcase<I>
364365
+ HasSolutions<I>
365366
+ HasLastFoundTime
@@ -420,6 +421,7 @@ where
420421
let corpus = if exec_res.is_corpus() {
421422
// Add the input to the main corpus
422423
let mut testcase = Testcase::from(input.clone());
424+
testcase.set_executions(*state.executions());
423425
#[cfg(feature = "track_hit_feedbacks")]
424426
self.feedback_mut()
425427
.append_hit_feedbacks(testcase.hit_feedbacks_mut())?;
@@ -435,6 +437,7 @@ where
435437
if exec_res.is_solution() {
436438
// The input is a solution, add it to the respective corpus
437439
let mut testcase = Testcase::from(input.clone());
440+
testcase.set_executions(*state.executions());
438441
testcase.add_metadata(*exit_kind);
439442
testcase.set_parent_id_optional(*state.corpus().current());
440443
if let Ok(mut tc) = state.current_testcase_mut() {
@@ -675,6 +678,7 @@ where
675678
let observers = executor.observers();
676679
// Always consider this to be "interesting"
677680
let mut testcase = Testcase::from(input.clone());
681+
testcase.set_executions(*state.executions());
678682

679683
// Maybe a solution
680684
#[cfg(not(feature = "introspection"))]
@@ -763,6 +767,7 @@ where
763767

764768
fn add_disabled_input(&mut self, state: &mut S, input: I) -> Result<CorpusId, Error> {
765769
let mut testcase = Testcase::from(input.clone());
770+
testcase.set_executions(*state.executions());
766771
testcase.set_disabled(true);
767772
// Add the disabled input to the main corpus
768773
let id = state.corpus_mut().add_disabled(testcase)?;

libafl/src/stages/tmin.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ where
284284
.feedback_mut()
285285
.is_interesting(state, manager, &base, &*observers, &exit_kind)?;
286286
let mut testcase = Testcase::from(base);
287+
testcase.set_executions(*state.executions());
288+
testcase.set_parent_id(base_corpus_id);
289+
287290
fuzzer
288291
.feedback_mut()
289292
.append_metadata(state, manager, &*observers, &mut testcase)?;

0 commit comments

Comments
 (0)