about summary refs log tree commit diff
path: root/src/afl-fuzz-run.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/afl-fuzz-run.c')
-rw-r--r--src/afl-fuzz-run.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/afl-fuzz-run.c b/src/afl-fuzz-run.c
index c5035b63..8f72d0fe 100644
--- a/src/afl-fuzz-run.c
+++ b/src/afl-fuzz-run.c
@@ -225,7 +225,7 @@ u8 run_target(char** argv, u32 timeout) {
   classify_counts((u64*)trace_bits);
 #else
   classify_counts((u32*)trace_bits);
-#endif                                                       /* ^WORD_SIZE_64 */
+#endif                                                     /* ^WORD_SIZE_64 */
 
   prev_timed_out = child_timed_out;
 
@@ -288,9 +288,16 @@ void write_to_testcase(void* mem, u32 len) {
 
   if (out_file) {
 
-    unlink(out_file);                                     /* Ignore errors. */
+    if (no_unlink) {
 
-    fd = open(out_file, O_WRONLY | O_CREAT | O_EXCL, 0600);
+      fd = open(out_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+
+    } else {
+
+      unlink(out_file);                                   /* Ignore errors. */
+      fd = open(out_file, O_WRONLY | O_CREAT | O_EXCL, 0600);
+
+    }
 
     if (fd < 0) PFATAL("Unable to create '%s'", out_file);
 
@@ -330,9 +337,16 @@ void write_with_gap(void* mem, u32 len, u32 skip_at, u32 skip_len) {
 
   if (out_file) {
 
-    unlink(out_file);                                     /* Ignore errors. */
+    if (no_unlink) {
+
+      fd = open(out_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+
+    } else {
 
-    fd = open(out_file, O_WRONLY | O_CREAT | O_EXCL, 0600);
+      unlink(out_file);                                   /* Ignore errors. */
+      fd = open(out_file, O_WRONLY | O_CREAT | O_EXCL, 0600);
+
+    }
 
     if (fd < 0) PFATAL("Unable to create '%s'", out_file);
 
@@ -760,9 +774,16 @@ u8 trim_case(char** argv, struct queue_entry* q, u8* in_buf) {
 
     s32 fd;
 
-    unlink(q->fname);                                      /* ignore errors */
+    if (no_unlink) {
+
+      fd = open(q->fname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
 
-    fd = open(q->fname, O_WRONLY | O_CREAT | O_EXCL, 0600);
+    } else {
+
+      unlink(q->fname);                                    /* ignore errors */
+      fd = open(q->fname, O_WRONLY | O_CREAT | O_EXCL, 0600);
+
+    }
 
     if (fd < 0) PFATAL("Unable to create '%s'", q->fname);