about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDominik Maier <domenukk@gmail.com>2020-03-01 13:46:57 +0100
committerDominik Maier <domenukk@gmail.com>2020-03-01 13:47:33 +0100
commit6865cd8d691385f805a63b62f9836abf98061e4f (patch)
tree59679277c4015b004894e1eaf5955216b5fcee49
parent59b80cb01e49804f1b6fabffa36514bb6a6a4fea (diff)
downloadafl++-6865cd8d691385f805a63b62f9836abf98061e4f.tar.gz
Added AFL_AUTORESUME option
-rw-r--r--docs/Changelog.md1
-rw-r--r--docs/env_variables.md4
-rw-r--r--include/afl-fuzz.h1
-rw-r--r--include/envs.h1
-rw-r--r--src/afl-fuzz-init.c20
-rw-r--r--src/afl-fuzz.c11
6 files changed, 30 insertions, 8 deletions
diff --git a/docs/Changelog.md b/docs/Changelog.md
index 2548a356..ab374596 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -13,6 +13,7 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
   - qemu_mode now uses solely the internal capstone version to fix builds
     on modern Linux distributions
   - more tools get environment variable usage info in the help output
+  - AFL_AUTORESUME will resume execution without the need to specify `-i -`
 
 
 ### Version ++2.62c (release):
diff --git a/docs/env_variables.md b/docs/env_variables.md
index fdc86a42..527f1c1b 100644
--- a/docs/env_variables.md
+++ b/docs/env_variables.md
@@ -265,6 +265,10 @@ checks or alter some of the more exotic semantics of the tool:
 
   - Setting AFL_NO_CPU_RED will not display very high cpu usages in red color.
 
+  - Setting AFL_AUTORESUME will resume a fuzz run (same as providing `-i -`)
+    for an existing out folder, even if a different `-i` was provided.
+    Without this setting, afl-fuzz will refuse execution for a long-fuzzed out dir.
+
   - Outdated environment variables that are that not supported anymore:
     AFL_DEFER_FORKSRV
     AFL_PERSISTENT
diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h
index 46bead3a..25764726 100644
--- a/include/afl-fuzz.h
+++ b/include/afl-fuzz.h
@@ -636,7 +636,6 @@ u32    find_start_position(void);
 void   find_timeout(void);
 double get_runnable_processes(void);
 void   nuke_resume_dir(void);
-void   maybe_delete_out_dir(void);
 void   setup_dirs_fds(void);
 void   setup_cmdline_file(char**);
 void   setup_stdio_file(void);
diff --git a/include/envs.h b/include/envs.h
index 0f7ed37a..306143be 100644
--- a/include/envs.h
+++ b/include/envs.h
@@ -1,6 +1,7 @@
 const char *afl_environment_variables[] = {
 
     "AFL_ALIGNED_ALLOC", "AFL_ALLOW_TMP", "AFL_ANALYZE_HEX", "AFL_AS",
+    "AFL_AUTORESUME",
     "AFL_AS_FORCE_INSTRUMENT", "AFL_BENCH_JUST_ONE", "AFL_BENCH_UNTIL_CRASH",
     "AFL_CAL_FAST", "AFL_CC", "AFL_CMIN_ALLOW_ANY", "AFL_CMIN_CRASHES_ONLY",
     "AFL_CODE_END", "AFL_CODE_START", "AFL_COMPCOV_BINNAME",
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");