about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorvanhauser-thc <vh@thc.org>2023-01-25 15:36:12 +0100
committervanhauser-thc <vh@thc.org>2023-01-25 15:36:19 +0100
commit90a259d5231242562d3cb2e62f2c8cdbf073b3a0 (patch)
tree177657f4c61c8d8b9b572ca79db9943978e9f896 /src
parent322e5e2fb63cb6f99da2df0f618ee89e547bcdb7 (diff)
downloadafl++-90a259d5231242562d3cb2e62f2c8cdbf073b3a0.tar.gz
new sanitizer option handling
Diffstat (limited to 'src')
-rw-r--r--src/afl-forkserver.c98
1 files changed, 43 insertions, 55 deletions
diff --git a/src/afl-forkserver.c b/src/afl-forkserver.c
index 9b8660ce..ef2fa904 100644
--- a/src/afl-forkserver.c
+++ b/src/afl-forkserver.c
@@ -689,69 +689,57 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
     if (!getenv("LD_BIND_LAZY")) { setenv("LD_BIND_NOW", "1", 1); }
 
     /* Set sane defaults for ASAN if nothing else is specified. */
+    u8 *have_asan_options = getenv("ASAN_OPTIONS");
+    u8 *have_ubsan_options = getenv("UBSAN_OPTIONS");
+    u8 *have_msan_options = getenv("MSAN_OPTIONS");
+    u8 *have_lsan_options = getenv("LSAN_OPTIONS");
+    u8  have_san_options = 0;
+    if (have_asan_options || have_ubsan_options || have_msan_options ||
+        have_lsan_options)
+      have_san_options = 1;
+    u8 default_options[1024] =
+        "detect_odr_violation=0:abort_on_error=1:symbolize=0:malloc_context_"
+        "size=0:allocator_may_return_null=1:handle_segv=0:handle_sigbus=0:"
+        "handle_abort=0:handle_sigfpe=0:handle_sigill=0:";
+
+    if (!have_lsan_options) strcat(default_options, "detect_leaks=0:");
 
-    if (!getenv("ASAN_OPTIONS"))
-      setenv("ASAN_OPTIONS",
-             "abort_on_error=1:"
-             "detect_leaks=0:"
-             "malloc_context_size=0:"
-             "symbolize=0:"
-             "allocator_may_return_null=1:"
-             "detect_odr_violation=0:"
-             "handle_segv=0:"
-             "handle_sigbus=0:"
-             "handle_abort=0:"
-             "handle_sigfpe=0:"
-             "handle_sigill=0",
-             1);
+    /* Set sane defaults for ASAN if nothing else is specified. */
+
+    if (!have_san_options) setenv("ASAN_OPTIONS", default_options, 1);
 
     /* Set sane defaults for UBSAN if nothing else is specified. */
 
-    if (!getenv("UBSAN_OPTIONS"))
-      setenv("UBSAN_OPTIONS",
-             "halt_on_error=1:"
-             "abort_on_error=1:"
-             "malloc_context_size=0:"
-             "allocator_may_return_null=1:"
-             "symbolize=0:"
-             "handle_segv=0:"
-             "handle_sigbus=0:"
-             "handle_abort=0:"
-             "handle_sigfpe=0:"
-             "handle_sigill=0",
-             1);
-
-    /* Envs for QASan */
-    setenv("QASAN_MAX_CALL_STACK", "0", 0);
-    setenv("QASAN_SYMBOLIZE", "0", 0);
+    if (!have_san_options) setenv("UBSAN_OPTIONS", default_options, 1);
 
     /* MSAN is tricky, because it doesn't support abort_on_error=1 at this
        point. So, we do this in a very hacky way. */
 
-    if (!getenv("MSAN_OPTIONS"))
-      setenv("MSAN_OPTIONS",
-           "exit_code=" STRINGIFY(MSAN_ERROR) ":"
-           "symbolize=0:"
-           "abort_on_error=1:"
-           "malloc_context_size=0:"
-           "allocator_may_return_null=1:"
-           "msan_track_origins=0:"
-           "handle_segv=0:"
-           "handle_sigbus=0:"
-           "handle_abort=0:"
-           "handle_sigfpe=0:"
-           "handle_sigill=0",
-           1);
-
-    /* LSAN, too, does not support abort_on_error=1. */
-
-    if (!getenv("LSAN_OPTIONS"))
-      setenv("LSAN_OPTIONS",
-            "exitcode=" STRINGIFY(LSAN_ERROR) ":"
-            "fast_unwind_on_malloc=0:"
-            "symbolize=0:"
-            "print_suppressions=0",
-            1);
+    if (!have_msan_options) {
+
+      u8 buf[2048] = "";
+      if (!have_san_options) strcpy(buf, default_options);
+      strcat(buf, "exit_code=" STRINGIFY(MSAN_ERROR) ":msan_track_origins=0:");
+      setenv("MSAN_OPTIONS", buf, 1);
+
+    }
+
+    /* LSAN, too, does not support abort_on_error=1. (is this still true??) */
+
+    if (!have_lsan_options) {
+
+      u8 buf[2048] = "";
+      if (!have_san_options) strcpy(buf, default_options);
+      strcat(buf,
+             "exitcode=" STRINGIFY(
+                 LSAN_ERROR) ":fast_unwind_on_malloc=0:print_suppressions=0:");
+      setenv("LSAN_OPTIONS", buf, 1);
+
+    }
+
+    /* Envs for QASan */
+    setenv("QASAN_MAX_CALL_STACK", "0", 0);
+    setenv("QASAN_SYMBOLIZE", "0", 0);
 
     fsrv->init_child_func(fsrv, argv);