about summary refs log tree commit diff
path: root/src/afl-fuzz-run.c
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2019-12-03 01:40:41 +0100
committerGitHub <noreply@github.com>2019-12-03 01:40:41 +0100
commit4231c498392484fd2187b9ed1dedb1ba7bc0958b (patch)
tree366586c4ceef17998670a8c2d978869bdac64d56 /src/afl-fuzz-run.c
parentb0d590fef4acb4b002429e4aec195e5740122494 (diff)
parentef2dc98773c55eb09e4c1a588fb74df58570f868 (diff)
downloadafl++-4231c498392484fd2187b9ed1dedb1ba7bc0958b.tar.gz
Merge branch 'master' into llvm_mode_build_fix
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);