@@ -217,7 +217,7 @@ pub trait Evaluator<E, EM, I, S> {
217
217
executor : & mut E ,
218
218
manager : & mut EM ,
219
219
input : I ,
220
- ) -> Result < ( CorpusId , ExecuteInputResult ) , Error > ;
220
+ ) -> Result < CorpusId , Error > ;
221
221
222
222
/// Adds the input to the corpus as a disabled input.
223
223
/// Used during initial corpus loading.
@@ -273,45 +273,15 @@ pub trait Fuzzer<E, EM, I, S, ST> {
273
273
iters : u64 ,
274
274
) -> Result < CorpusId , Error > ;
275
275
}
276
-
277
- /// The corpus this input should be added to
278
- #[ derive( Debug , PartialEq , Eq , Default ) ]
279
- pub struct ExecuteInputResult {
280
- is_corpus : bool ,
281
- is_solution : bool ,
282
- }
283
-
284
- impl ExecuteInputResult {
285
- /// Constructor
286
- #[ must_use]
287
- pub fn new ( is_corpus : bool , is_solution : bool ) -> Self {
288
- Self {
289
- is_corpus,
290
- is_solution,
291
- }
292
- }
293
-
294
- /// if this is corpus worthy
295
- #[ must_use]
296
- pub fn is_corpus ( & self ) -> bool {
297
- self . is_corpus
298
- }
299
-
300
- /// if this is solution worthy
301
- #[ must_use]
302
- pub fn is_solution ( & self ) -> bool {
303
- self . is_solution
304
- }
305
-
306
- /// tell that this is corpus
307
- pub fn set_is_corpus ( & mut self , v : bool ) {
308
- self . is_corpus = v;
309
- }
310
-
311
- /// tell that this is solution
312
- pub fn set_is_solution ( & mut self , v : bool ) {
313
- self . is_solution = v;
314
- }
276
+ /// The result of harness execution
277
+ #[ derive( Debug , PartialEq , Eq ) ]
278
+ pub enum ExecuteInputResult {
279
+ /// No special input
280
+ None ,
281
+ /// This input should be stored in the corpus
282
+ Corpus ,
283
+ /// This input leads to a solution
284
+ Solution ,
315
285
}
316
286
317
287
/// Your default fuzzer instance, for everyday use.
@@ -403,7 +373,7 @@ where
403
373
observers : & OT ,
404
374
exit_kind : & ExitKind ,
405
375
) -> Result < ExecuteInputResult , Error > {
406
- let mut res = ExecuteInputResult :: default ( ) ;
376
+ let mut res = ExecuteInputResult :: None ;
407
377
408
378
#[ cfg( not( feature = "introspection" ) ) ]
409
379
let is_solution = self
@@ -416,22 +386,21 @@ where
416
386
. is_interesting_introspection ( state, manager, input, observers, exit_kind) ?;
417
387
418
388
if is_solution {
419
- res. set_is_solution ( true ) ;
420
- }
421
-
422
- # [ cfg ( not ( feature = "introspection" ) ) ]
423
- let corpus_worthy = self
424
- . feedback_mut ( )
425
- . is_interesting ( state , manager , input , observers , exit_kind ) ? ;
426
- # [ cfg ( feature = "introspection" ) ]
427
- let corpus_worthy = self
428
- . feedback_mut ( )
429
- . is_interesting_introspection ( state , manager , input , observers , exit_kind ) ? ;
430
-
431
- if corpus_worthy {
432
- res . set_is_corpus ( true ) ;
389
+ res = ExecuteInputResult :: Solution ;
390
+ } else {
391
+ # [ cfg ( not ( feature = "introspection" ) ) ]
392
+ let corpus_worthy = self
393
+ . feedback_mut ( )
394
+ . is_interesting ( state , manager , input , observers , exit_kind ) ? ;
395
+ # [ cfg ( feature = "introspection" ) ]
396
+ let corpus_worthy = self
397
+ . feedback_mut ( )
398
+ . is_interesting_introspection ( state , manager , input , observers , exit_kind ) ? ;
399
+
400
+ if corpus_worthy {
401
+ res = ExecuteInputResult :: Corpus ;
402
+ }
433
403
}
434
-
435
404
Ok ( res)
436
405
}
437
406
@@ -444,42 +413,42 @@ where
444
413
manager : & mut EM ,
445
414
input : & I ,
446
415
exec_res : & ExecuteInputResult ,
447
- exit_kind : & ExitKind ,
416
+ _exit_kind : & ExitKind ,
448
417
observers : & OT ,
449
418
) -> Result < Option < CorpusId > , Error > {
450
- let corpus = if exec_res. is_corpus ( ) {
451
- // Add the input to the main corpus
452
- let mut testcase = Testcase :: from ( input. clone ( ) ) ;
453
- testcase. set_executions ( * state. executions ( ) ) ;
454
- #[ cfg( feature = "track_hit_feedbacks" ) ]
455
- self . feedback_mut ( )
456
- . append_hit_feedbacks ( testcase. hit_feedbacks_mut ( ) ) ?;
457
- self . feedback_mut ( )
458
- . append_metadata ( state, manager, observers, & mut testcase) ?;
459
- let id = state. corpus_mut ( ) . add ( testcase) ?;
460
- self . scheduler_mut ( ) . on_add ( state, id) ?;
461
- Ok ( Some ( id) )
462
- } else {
463
- Ok ( None )
464
- } ;
465
-
466
- if exec_res. is_solution ( ) {
467
- // The input is a solution, add it to the respective corpus
468
- let mut testcase = Testcase :: from ( input. clone ( ) ) ;
469
- testcase. set_executions ( * state. executions ( ) ) ;
470
- testcase. add_metadata ( * exit_kind) ;
471
- testcase. set_parent_id_optional ( * state. corpus ( ) . current ( ) ) ;
472
- if let Ok ( mut tc) = state. current_testcase_mut ( ) {
473
- tc. found_objective ( ) ;
419
+ match exec_res {
420
+ ExecuteInputResult :: None => Ok ( None ) ,
421
+ ExecuteInputResult :: Corpus => {
422
+ // Not a solution
423
+ // Add the input to the main corpus
424
+ let mut testcase = Testcase :: from ( input. clone ( ) ) ;
425
+ #[ cfg( feature = "track_hit_feedbacks" ) ]
426
+ self . feedback_mut ( )
427
+ . append_hit_feedbacks ( testcase. hit_feedbacks_mut ( ) ) ?;
428
+ self . feedback_mut ( )
429
+ . append_metadata ( state, manager, observers, & mut testcase) ?;
430
+ let id = state. corpus_mut ( ) . add ( testcase) ?;
431
+ self . scheduler_mut ( ) . on_add ( state, id) ?;
432
+
433
+ Ok ( Some ( id) )
434
+ }
435
+ ExecuteInputResult :: Solution => {
436
+ // The input is a solution, add it to the respective corpus
437
+ let mut testcase = Testcase :: from ( input. clone ( ) ) ;
438
+ testcase. set_parent_id_optional ( * state. corpus ( ) . current ( ) ) ;
439
+ if let Ok ( mut tc) = state. current_testcase_mut ( ) {
440
+ tc. found_objective ( ) ;
441
+ }
442
+ #[ cfg( feature = "track_hit_feedbacks" ) ]
443
+ self . objective_mut ( )
444
+ . append_hit_feedbacks ( testcase. hit_objectives_mut ( ) ) ?;
445
+ self . objective_mut ( )
446
+ . append_metadata ( state, manager, observers, & mut testcase) ?;
447
+ state. solutions_mut ( ) . add ( testcase) ?;
448
+
449
+ Ok ( None )
474
450
}
475
- #[ cfg( feature = "track_hit_feedbacks" ) ]
476
- self . objective_mut ( )
477
- . append_hit_feedbacks ( testcase. hit_objectives_mut ( ) ) ?;
478
- self . objective_mut ( )
479
- . append_metadata ( state, manager, observers, & mut testcase) ?;
480
- state. solutions_mut ( ) . add ( testcase) ?;
481
451
}
482
- corpus
483
452
}
484
453
485
454
fn serialize_and_dispatch (
@@ -492,14 +461,20 @@ where
492
461
exit_kind : & ExitKind ,
493
462
) -> Result < ( ) , Error > {
494
463
// Now send off the event
495
- let observers_buf = if exec_res. is_corpus ( )
496
- && manager. should_send ( )
497
- && manager. configuration ( ) != EventConfig :: AlwaysUnique
498
- {
499
- // TODO set None for fast targets
500
- Some ( postcard:: to_allocvec ( observers) ?)
501
- } else {
502
- None
464
+ let observers_buf = match exec_res {
465
+ ExecuteInputResult :: Corpus => {
466
+ if manager. should_send ( ) {
467
+ // TODO set None for fast targets
468
+ if manager. configuration ( ) == EventConfig :: AlwaysUnique {
469
+ None
470
+ } else {
471
+ Some ( postcard:: to_allocvec ( observers) ?)
472
+ }
473
+ } else {
474
+ None
475
+ }
476
+ }
477
+ _ => None ,
503
478
} ;
504
479
505
480
self . dispatch_event ( state, manager, input, exec_res, observers_buf, exit_kind) ?;
@@ -516,38 +491,42 @@ where
516
491
exit_kind : & ExitKind ,
517
492
) -> Result < ( ) , Error > {
518
493
// Now send off the event
519
- if manager. should_send ( ) {
520
- if exec_res. is_corpus ( ) {
521
- manager. fire (
522
- state,
523
- EventWithStats :: with_current_time (
524
- Event :: NewTestcase {
525
- input : input. clone ( ) ,
526
- observers_buf,
527
- exit_kind : * exit_kind,
528
- corpus_size : state. corpus ( ) . count ( ) ,
529
- client_config : manager. configuration ( ) ,
530
- forward_id : None ,
531
- #[ cfg( all( unix, feature = "std" , feature = "multi_machine" ) ) ]
532
- node_id : None ,
533
- } ,
534
- * state. executions ( ) ,
535
- ) ,
536
- ) ?;
494
+ match exec_res {
495
+ ExecuteInputResult :: Corpus => {
496
+ if manager. should_send ( ) {
497
+ manager. fire (
498
+ state,
499
+ EventWithStats :: with_current_time (
500
+ Event :: NewTestcase {
501
+ input : input. clone ( ) ,
502
+ observers_buf,
503
+ exit_kind : * exit_kind,
504
+ corpus_size : state. corpus ( ) . count ( ) ,
505
+ client_config : manager. configuration ( ) ,
506
+ forward_id : None ,
507
+ #[ cfg( all( unix, feature = "std" , feature = "multi_machine" ) ) ]
508
+ node_id : None ,
509
+ } ,
510
+ * state. executions ( ) ,
511
+ ) ,
512
+ ) ?;
513
+ }
537
514
}
538
-
539
- if exec_res. is_solution ( ) {
540
- manager. fire (
541
- state,
542
- EventWithStats :: with_current_time (
543
- Event :: Objective {
544
- input : self . share_objectives . then_some ( input. clone ( ) ) ,
545
- objective_size : state. solutions ( ) . count ( ) ,
546
- } ,
547
- * state. executions ( ) ,
548
- ) ,
549
- ) ?;
515
+ ExecuteInputResult :: Solution => {
516
+ if manager. should_send ( ) {
517
+ manager. fire (
518
+ state,
519
+ EventWithStats :: with_current_time (
520
+ Event :: Objective {
521
+ input : self . share_objectives . then_some ( input. clone ( ) ) ,
522
+ objective_size : state. solutions ( ) . count ( ) ,
523
+ } ,
524
+ * state. executions ( ) ,
525
+ ) ,
526
+ ) ?;
527
+ }
550
528
}
529
+ ExecuteInputResult :: None => ( ) ,
551
530
}
552
531
553
532
Ok ( ( ) )
@@ -568,7 +547,7 @@ where
568
547
if send_events {
569
548
self . serialize_and_dispatch ( state, manager, input, & exec_res, observers, exit_kind) ?;
570
549
}
571
- if exec_res. is_corpus ( ) || exec_res . is_solution ( ) {
550
+ if exec_res != ExecuteInputResult :: None {
572
551
* state. last_found_time_mut ( ) = current_time ( ) ;
573
552
}
574
553
Ok ( ( exec_res, corpus_id) )
@@ -687,7 +666,7 @@ where
687
666
if self . input_filter . should_execute ( input) {
688
667
self . evaluate_input ( state, executor, manager, input)
689
668
} else {
690
- Ok ( ( ExecuteInputResult :: default ( ) , None ) )
669
+ Ok ( ( ExecuteInputResult :: None , None ) )
691
670
}
692
671
}
693
672
@@ -712,7 +691,7 @@ where
712
691
executor : & mut E ,
713
692
manager : & mut EM ,
714
693
input : I ,
715
- ) -> Result < ( CorpusId , ExecuteInputResult ) , Error > {
694
+ ) -> Result < CorpusId , Error > {
716
695
* state. last_found_time_mut ( ) = current_time ( ) ;
717
696
718
697
let exit_kind = self . execute_input ( state, executor, manager, & input) ?;
@@ -743,7 +722,7 @@ where
743
722
self . objective_mut ( )
744
723
. append_metadata ( state, manager, & * observers, & mut testcase) ?;
745
724
// we don't care about solution id
746
- let _ = state. solutions_mut ( ) . add ( testcase. clone ( ) ) ?;
725
+ let id = state. solutions_mut ( ) . add ( testcase) ?;
747
726
748
727
manager. fire (
749
728
state,
@@ -755,17 +734,19 @@ where
755
734
* state. executions ( ) ,
756
735
) ,
757
736
) ?;
737
+
738
+ return Ok ( id) ;
758
739
}
759
740
760
741
// several is_interesting implementations collect some data about the run, later used in
761
742
// append_metadata; we *must* invoke is_interesting here to collect it
762
743
#[ cfg( not( feature = "introspection" ) ) ]
763
- let corpus_worthy =
744
+ let _corpus_worthy =
764
745
self . feedback_mut ( )
765
746
. is_interesting ( state, manager, & input, & * observers, & exit_kind) ?;
766
747
767
748
#[ cfg( feature = "introspection" ) ]
768
- let corpus_worthy = self . feedback_mut ( ) . is_interesting_introspection (
749
+ let _corpus_worthy = self . feedback_mut ( ) . is_interesting_introspection (
769
750
state,
770
751
manager,
771
752
& input,
@@ -803,7 +784,7 @@ where
803
784
* state. executions ( ) ,
804
785
) ,
805
786
) ?;
806
- Ok ( ( id , ExecuteInputResult :: new ( corpus_worthy , is_solution ) ) )
787
+ Ok ( id )
807
788
}
808
789
809
790
fn add_disabled_input ( & mut self , state : & mut S , input : I ) -> Result < CorpusId , Error > {
0 commit comments