From dffd6537ae0fc966dca368856f33e6ff3bc898e3 Mon Sep 17 00:00:00 2001 From: Kuang-che Wu Date: Thu, 15 May 2025 18:07:15 +0800 Subject: [PATCH] avoid duplicated code --- src/afl-fuzz-init.c | 81 ++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 48 deletions(-) diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c index fd3fabf7..de453cf6 100644 --- a/src/afl-fuzz-init.c +++ b/src/afl-fuzz-init.c @@ -1413,65 +1413,50 @@ void perform_dry_run(afl_state_t *afl) { if (!q || q->disabled || q->cal_failed || !q->exec_cksum) { continue; } u32 done = 0; - for (i = idx + 1; - likely(i < afl->queued_items && afl->queue_buf[i] && !done); ++i) { + for (i = idx + 1; likely(i < afl->queued_items && afl->queue_buf[i]); ++i) { struct queue_entry *p = afl->queue_buf[i]; if (p->disabled || p->cal_failed || !p->exec_cksum) { continue; } + if (p->exec_cksum != q->exec_cksum) continue; - if (p->exec_cksum == q->exec_cksum) { + duplicates = 1; - duplicates = 1; + // we keep the shorter file + struct queue_entry *to_disable, *to_keep; + if (p->len >= q->len) { - // we keep the shorter file - if (p->len >= q->len) { + to_disable = p; + to_keep = q; - if (!p->was_fuzzed) { + } else { - p->was_fuzzed = 1; - afl->reinit_table = 1; - --afl->pending_not_fuzzed; - --afl->active_items; - - } - - p->disabled = 1; - p->perf_score = 0; - - if (afl->debug) { - - WARNF("Same coverage - %s is kept active, %s is disabled.", - q->fname, p->fname); - - } - - } else { - - if (!q->was_fuzzed) { - - q->was_fuzzed = 1; - afl->reinit_table = 1; - --afl->pending_not_fuzzed; - --afl->active_items; - - } - - q->disabled = 1; - q->perf_score = 0; - - if (afl->debug) { - - WARNF("Same coverage - %s is kept active, %s is disabled.", - p->fname, q->fname); - - } - - done = 1; // end inner loop because outer loop entry is disabled now - - } + to_disable = q; + to_keep = p; } + if (!to_disable->was_fuzzed) { + + to_disable->was_fuzzed = 1; + afl->reinit_table = 1; + --afl->pending_not_fuzzed; + --afl->active_items; + + } + + to_disable->disabled = 1; + to_disable->perf_score = 0; + + if (afl->debug) { + + WARNF("Same coverage - %s is kept active, %s is disabled.", + to_keep->fname, to_disable->fname); + + } + + // end inner loop because outer loop entry is disabled now + if (to_disable == q) break; + } }