about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2021-02-02 10:05:10 +0100
committervan Hauser <vh@thc.org>2021-02-02 10:05:10 +0100
commit1f71b85426f837ebcae8381897d44a3a67c73a4f (patch)
tree15ccc8daf4a949506f9353d3ddefd9a72f4f4f43 /src
parent654f389e73c9fd5b7e141b33ea28ab0fdda3178f (diff)
downloadafl++-1f71b85426f837ebcae8381897d44a3a67c73a4f.tar.gz
automagically fix sanitize fuzzer+coverage
Diffstat (limited to 'src')
-rw-r--r--src/afl-cc.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/afl-cc.c b/src/afl-cc.c
index f272f0b5..cba435bd 100644
--- a/src/afl-cc.c
+++ b/src/afl-cc.c
@@ -693,6 +693,38 @@ static void edit_params(u32 argc, char **argv, char **envp) {
     if (strstr(cur, "afl-compiler-rt") || strstr(cur, "afl-llvm-rt")) continue;
     if (!strcmp(cur, "-Wl,-z,defs") || !strcmp(cur, "-Wl,--no-undefined"))
       continue;
+    if (!strncmp(cur, "-fsanitize=fuzzer-", strlen("-fsanitize=fuzzer-")) ||
+        !strncmp(cur, "-fsanitize-coverage", strlen("-fsanitize-coverage"))) {
+
+      if (!be_quiet) { WARNF("Found '%s' - stripping!", cur); }
+      continue;
+
+    }
+
+    if (!strcmp(cur, "-fsanitize=fuzzer")) {
+
+      u8 *afllib = find_object("libAFLDriver.a", argv[0]);
+
+      if (!be_quiet)
+        WARNF(
+            "Found errornous '-fsanitize=fuzzer', trying to replace with "
+            "libAFLDriver.a");
+
+      if (!afllib) {
+
+        WARNF(
+            "Cannot find 'libAFLDriver.a' to replace a wrong "
+            "'-fsanitize=fuzzer' in the flags - this will fail!");
+
+      } else {
+
+        cc_params[cc_par_cnt++] = afllib;
+
+      }
+
+      continue;
+
+    }
 
     if (!strcmp(cur, "-m32")) bit_mode = 32;
     if (!strcmp(cur, "armv7a-linux-androideabi")) bit_mode = 32;
@@ -802,8 +834,7 @@ static void edit_params(u32 argc, char **argv, char **envp) {
   }
 
 #if defined(USEMMAP) && !defined(__HAIKU__)
-  if (!have_c)
-    cc_params[cc_par_cnt++] = "-lrt";
+  if (!have_c) cc_params[cc_par_cnt++] = "-lrt";
 #endif
 
   cc_params[cc_par_cnt++] = "-D__AFL_HAVE_MANUAL_CONTROL=1";
@@ -976,12 +1007,11 @@ static void edit_params(u32 argc, char **argv, char **envp) {
   #endif
 
   #if defined(USEMMAP) && !defined(__HAIKU__)
-    if (!have_c)
-      cc_params[cc_par_cnt++] = "-lrt";
+    if (!have_c) cc_params[cc_par_cnt++] = "-lrt";
   #endif
 
-   // prevent unnecessary build errors
-   cc_params[cc_par_cnt++] = "-Wno-unused-command-line-argument";
+    // prevent unnecessary build errors
+    cc_params[cc_par_cnt++] = "-Wno-unused-command-line-argument";
 
   }