From 6865cd8d691385f805a63b62f9836abf98061e4f Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 1 Mar 2020 13:46:57 +0100 Subject: Added AFL_AUTORESUME option --- src/afl-fuzz-init.c | 20 +++++++++++++++----- src/afl-fuzz.c | 11 +++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c index 632cdf6b..6e7d3f74 100644 --- a/src/afl-fuzz-init.c +++ b/src/afl-fuzz-init.c @@ -894,7 +894,7 @@ void find_timeout(void) { } -/* A helper function for maybe_delete_out_dir(), deleting all prefixed +/* A helper function for handle_existing_out_dir(), deleting all prefixed files in a directory. */ static u8 delete_files(u8* path, u8* prefix) { @@ -1018,9 +1018,10 @@ dir_cleanup_failed: } /* Delete fuzzer output directory if we recognize it as ours, if the fuzzer - is not currently running, and if the last run time isn't too great. */ + is not currently running, and if the last run time isn't too great. + Resume fuzzing if `-` is set as in_dir or if AFL_AUTORESUME is set */ -void maybe_delete_out_dir(void) { +static void handle_existing_out_dir(void) { FILE* f; u8* fn = alloc_printf("%s/fuzzer_stats", out_dir); @@ -1063,6 +1064,15 @@ void maybe_delete_out_dir(void) { fclose(f); + /* Autoresume treats a normal run as in_place_resume if a valid out dir already exists */ + + if (getenv("AFL_AUTORESUME")) { + + OKF("Detected prior run with AFL_AUTORESUME set. Resuming."); + in_place_resume = 1; + + } + /* Let's see how much work is at stake. */ if (!in_place_resume && last_update - start_time2 > OUTPUT_GRACE * 60) { @@ -1079,7 +1089,7 @@ void maybe_delete_out_dir(void) { " or specify a different output location for this job. To resume " "the old\n" " session, put '-' as the input directory in the command line " - "('-i -') and\n" + "('-i -') or set the AFL_AUTORESUME=1 env variable and\n" " try again.\n", OUTPUT_GRACE); @@ -1306,7 +1316,7 @@ void setup_dirs_fds(void) { if (errno != EEXIST) PFATAL("Unable to create '%s'", out_dir); - maybe_delete_out_dir(); + handle_existing_out_dir(); } else { diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index c7f8ccad..d4c75d9c 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -314,7 +314,14 @@ int main(int argc, char** argv, char** envp) { if (in_dir) FATAL("Multiple -i options not supported"); in_dir = optarg; - if (!strcmp(in_dir, "-")) in_place_resume = 1; + if (!strcmp(in_dir, "-")) { + + if (getenv("AFL_AUTORESUME")) + WARNF("AFL_AUTORESUME has no effect for '-i -'"); + + in_place_resume = 1; + + } break; @@ -649,7 +656,7 @@ int main(int argc, char** argv, char** envp) { usage(argv[0], show_help); OKF("afl++ is maintained by Marc \"van Hauser\" Heuse, Heiko \"hexcoder\" " - "Eißfeldt and Andrea Fioraldi"); + "Eißfeldt, Andrea Fioraldi and Dominik Maier"); OKF("afl++ is open source, get it at " "https://github.com/vanhauser-thc/AFLplusplus"); OKF("Power schedules from github.com/mboehme/aflfast"); -- cgit 1.4.1 From 3e0a3ec45fe35f62a293d86139913ecf45670535 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 1 Mar 2020 14:09:21 +0100 Subject: migrated autoresume to use get_afl_env --- include/afl-fuzz.h | 1 + src/afl-fuzz-globals.c | 1 + src/afl-fuzz-init.c | 2 +- src/afl-fuzz.c | 17 +++++++++-------- 4 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h index 25764726..1999f16c 100644 --- a/include/afl-fuzz.h +++ b/include/afl-fuzz.h @@ -315,6 +315,7 @@ extern u8 skip_deterministic, /* Skip deterministic stages? */ no_forkserver, /* Disable forkserver? */ crash_mode, /* Crash mode! Yeah! */ in_place_resume, /* Attempt in-place resume? */ + autoresume, /* Resume if out_dir exists? */ auto_changed, /* Auto-generated tokens changed? */ no_cpu_meter_red, /* Feng shui on the status screen */ no_arith, /* Skip most arithmetic ops */ diff --git a/src/afl-fuzz-globals.c b/src/afl-fuzz-globals.c index fc71d29d..ae343026 100644 --- a/src/afl-fuzz-globals.c +++ b/src/afl-fuzz-globals.c @@ -115,6 +115,7 @@ u8 skip_deterministic, /* Skip deterministic stages? */ no_forkserver, /* Disable forkserver? */ crash_mode, /* Crash mode! Yeah! */ in_place_resume, /* Attempt in-place resume? */ + autoresume, /* Resume if out_dir exists? */ auto_changed, /* Auto-generated tokens changed? */ no_cpu_meter_red, /* Feng shui on the status screen */ no_arith, /* Skip most arithmetic ops */ diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c index 6e7d3f74..a82fa8f9 100644 --- a/src/afl-fuzz-init.c +++ b/src/afl-fuzz-init.c @@ -1066,7 +1066,7 @@ static void handle_existing_out_dir(void) { /* Autoresume treats a normal run as in_place_resume if a valid out dir already exists */ - if (getenv("AFL_AUTORESUME")) { + if (!in_place_resume && autoresume) { OKF("Detected prior run with AFL_AUTORESUME set. Resuming."); in_place_resume = 1; diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index d4c75d9c..98c9dbe3 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -314,14 +314,7 @@ int main(int argc, char** argv, char** envp) { if (in_dir) FATAL("Multiple -i options not supported"); in_dir = optarg; - if (!strcmp(in_dir, "-")) { - - if (getenv("AFL_AUTORESUME")) - WARNF("AFL_AUTORESUME has no effect for '-i -'"); - - in_place_resume = 1; - - } + if (!strcmp(in_dir, "-")) in_place_resume = 1; break; @@ -757,6 +750,14 @@ int main(int argc, char** argv, char** envp) { if (get_afl_env("AFL_SHUFFLE_QUEUE")) shuffle_queue = 1; if (get_afl_env("AFL_FAST_CAL")) fast_cal = 1; + if (get_afl_env("AFL_AUTORESUME")) { + + autoresume = 1; + if (in_place_resume) + WARNF("AFL_AUTORESUME has no effect for '-i -'"); + + } + if (get_afl_env("AFL_HANG_TMOUT")) { hang_tmout = atoi(getenv("AFL_HANG_TMOUT")); -- cgit 1.4.1 From 43e97a5aa24744c5c4abd04041a099bd2c3eec12 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Mon, 2 Mar 2020 16:10:08 +0100 Subject: Autoresume added to help --- src/afl-fuzz.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index 98c9dbe3..548f029b 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -186,6 +186,7 @@ static void usage(u8* argv0, int more_help) { //"AFL_DEFER_FORKSRV: not supported anymore -> no effect, just a warning\n" "AFL_EXIT_WHEN_DONE: exit when all inputs are run and no new finds are found\n" "AFL_BENCH_UNTIL_CRASH: exit soon when the first crashing input has been found\n" + "AFL_AUTORESUME: resume fuzzing if directory specified by -o already exists\n" "\n" ); else @@ -754,7 +755,7 @@ int main(int argc, char** argv, char** envp) { autoresume = 1; if (in_place_resume) - WARNF("AFL_AUTORESUME has no effect for '-i -'"); + SAYF("AFL_AUTORESUME has no effect for '-i -'"); } -- cgit 1.4.1