Skip to content

Commit d80cedc

Browse files
Merge pull request #1677 from AFLplusplus/classify
Classify
2 parents bd3855f + 7a650e4 commit d80cedc

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/afl-fuzz-bitmap.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,13 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) {
475475
only be used for special schedules */
476476
if (unlikely(afl->schedule >= FAST && afl->schedule <= RARE)) {
477477

478+
classify_counts(&afl->fsrv);
479+
classified = 1;
480+
478481
cksum = hash64(afl->fsrv.trace_bits, afl->fsrv.map_size, HASH_CONST);
479482

480483
/* Saturated increment */
481-
if (afl->n_fuzz[cksum % N_FUZZ_SIZE] < 0xFFFFFFFF)
484+
if (likely(afl->n_fuzz[cksum % N_FUZZ_SIZE] < 0xFFFFFFFF))
482485
afl->n_fuzz[cksum % N_FUZZ_SIZE]++;
483486

484487
}
@@ -488,7 +491,15 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) {
488491
/* Keep only if there are new bits in the map, add to queue for
489492
future fuzzing, etc. */
490493

491-
new_bits = has_new_bits_unclassified(afl, afl->virgin_bits);
494+
if (likely(classified)) {
495+
496+
new_bits = has_new_bits(afl, afl->virgin_bits);
497+
498+
} else {
499+
500+
new_bits = has_new_bits_unclassified(afl, afl->virgin_bits);
501+
502+
}
492503

493504
if (likely(!new_bits)) {
494505

@@ -497,8 +508,6 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) {
497508

498509
}
499510

500-
classified = new_bits;
501-
502511
save_to_queue:
503512

504513
#ifndef SIMPLE_FILES
@@ -556,21 +565,21 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) {
556565

557566
}
558567

559-
/* AFLFast schedule? update the new queue entry */
560-
if (cksum) {
568+
if (unlikely(!classified && new_bits)) {
561569

562-
afl->queue_top->n_fuzz_entry = cksum % N_FUZZ_SIZE;
563-
afl->n_fuzz[afl->queue_top->n_fuzz_entry] = 1;
570+
/* due to classify counts we have to recalculate the checksum */
571+
afl->queue_top->exec_cksum =
572+
hash64(afl->fsrv.trace_bits, afl->fsrv.map_size, HASH_CONST);
573+
classified = 1;
564574

565575
}
566576

567-
/* due to classify counts we have to recalculate the checksum */
568-
afl->queue_top->exec_cksum =
569-
hash64(afl->fsrv.trace_bits, afl->fsrv.map_size, HASH_CONST);
577+
/* For AFLFast schedules we update the new queue entry */
578+
afl->queue_top->n_fuzz_entry = cksum % N_FUZZ_SIZE;
579+
afl->n_fuzz[afl->queue_top->n_fuzz_entry] = 1;
570580

571581
/* Try to calibrate inline; this also calls update_bitmap_score() when
572582
successful. */
573-
574583
res = calibrate_case(afl, afl->queue_top, mem, afl->queue_cycle - 1, 0);
575584

576585
if (unlikely(res == FSRV_RUN_ERROR)) {
@@ -604,7 +613,7 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) {
604613

605614
if (likely(!afl->non_instrumented_mode)) {
606615

607-
if (!classified) {
616+
if (unlikely(!classified)) {
608617

609618
classify_counts(&afl->fsrv);
610619
classified = 1;
@@ -729,7 +738,12 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) {
729738

730739
if (likely(!afl->non_instrumented_mode)) {
731740

732-
if (!classified) { classify_counts(&afl->fsrv); }
741+
if (unlikely(!classified)) {
742+
743+
classify_counts(&afl->fsrv);
744+
classified = 1;
745+
746+
}
733747

734748
simplify_trace(afl, afl->fsrv.trace_bits);
735749

0 commit comments

Comments
 (0)