about summary refs log tree commit diff
path: root/instrumentation/afl-compiler-rt.o.c
diff options
context:
space:
mode:
Diffstat (limited to 'instrumentation/afl-compiler-rt.o.c')
-rw-r--r--instrumentation/afl-compiler-rt.o.c87
1 files changed, 46 insertions, 41 deletions
diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c
index 037caaf0..4c5d4e79 100644
--- a/instrumentation/afl-compiler-rt.o.c
+++ b/instrumentation/afl-compiler-rt.o.c
@@ -83,8 +83,8 @@
 #include <sys/mman.h>
 #include <fcntl.h>
 
-#ifdef AFL_PERSISTENT_REPLAY
-  #include "persistent_replay.h"
+#ifdef AFL_PERSISTENT_RECORD
+  #include "afl-persistent-replay.h"
 #endif
 
 /* Globals needed by the injected instrumentation. The __afl_area_initial region
@@ -1342,68 +1342,73 @@ int __afl_persistent_loop(unsigned int max_cnt) {
   static u8  first_pass = 1;
   static u32 cycle_cnt;
 
-#ifdef AFL_PERSISTENT_REPLAY
+#ifdef AFL_PERSISTENT_RECORD
+  char tcase[PATH_MAX];
+#endif
 
-  #ifndef PATH_MAX
-    #define PATH_MAX 4096
-  #endif
+  if (first_pass) {
 
-  static u8 inited = 0;
-  char      tcase[PATH_MAX];
+    /* Make sure that every iteration of __AFL_LOOP() starts with a clean slate.
+       On subsequent calls, the parent will take care of that, but on the first
+       iteration, it's our job to erase any trace of whatever happened
+       before the loop. */
 
-  if (unlikely(is_replay_record)) {
+    memset(__afl_area_ptr, 0, __afl_map_size);
+    __afl_area_ptr[0] = 1;
+    memset(__afl_prev_loc, 0, NGRAM_SIZE_MAX * sizeof(PREV_LOC_T));
 
-    if (!inited) {
+    first_pass = 0;
+    __afl_selective_coverage_temp = 1;
+
+#ifdef AFL_PERSISTENT_RECORD
+    if (unlikely(is_replay_record)) {
 
       cycle_cnt = replay_record_cnt;
-      inited = 1;
+      goto persistent_record;
 
-    }
+    } else
 
-    snprintf(tcase, PATH_MAX, "%s/%s",
-             replay_record_dir ? replay_record_dir : "./",
-             record_list[replay_record_cnt - cycle_cnt]->d_name);
+#endif
+    {
 
-  #ifdef AFL_PERSISTENT_REPLAY_ARGPARSE
-    if (record_arg) {
+      cycle_cnt = max_cnt;
 
-      *record_arg = tcase;
+    }
 
-    } else
+    return 1;
 
-  #endif  // AFL_PERSISTENT_REPLAY_ARGPARSE
-    {
+  } else if (--cycle_cnt) {
 
-      int fd = open(tcase, O_RDONLY);
-      dup2(fd, 0);
-      close(fd);
+#ifdef AFL_PERSISTENT_RECORD
+    if (unlikely(is_replay_record)) {
 
-    }
+    persistent_record:
 
-    return cycle_cnt--;
+      snprintf(tcase, PATH_MAX, "%s/%s",
+               replay_record_dir ? replay_record_dir : "./",
+               record_list[replay_record_cnt - cycle_cnt]->d_name);
 
-  } else
+  #ifdef AFL_PERSISTENT_REPLAY_ARGPARSE
+      if (unlikely(record_arg)) {
 
-#endif
+        *record_arg = tcase;
 
-      if (first_pass) {
+      } else
 
-    /* Make sure that every iteration of __AFL_LOOP() starts with a clean slate.
-       On subsequent calls, the parent will take care of that, but on the first
-       iteration, it's our job to erase any trace of whatever happened
-       before the loop. */
+  #endif  // AFL_PERSISTENT_REPLAY_ARGPARSE
+      {
 
-    memset(__afl_area_ptr, 0, __afl_map_size);
-    __afl_area_ptr[0] = 1;
-    memset(__afl_prev_loc, 0, NGRAM_SIZE_MAX * sizeof(PREV_LOC_T));
+        int fd = open(tcase, O_RDONLY);
+        dup2(fd, 0);
+        close(fd);
 
-    cycle_cnt = max_cnt;
-    first_pass = 0;
-    __afl_selective_coverage_temp = 1;
+      }
 
-    return 1;
+      return 1;
 
-  } else if (--cycle_cnt) {
+    }
+
+#endif
 
     raise(SIGSTOP);