diff options
-rw-r--r-- | include/common.h | 1 | ||||
-rw-r--r-- | src/afl-analyze.c | 14 | ||||
-rw-r--r-- | src/afl-common.c | 13 | ||||
-rw-r--r-- | src/afl-forkserver.c | 3 | ||||
-rw-r--r-- | src/afl-fuzz-cmplog.c | 2 | ||||
-rw-r--r-- | src/afl-fuzz-globals.c | 1 | ||||
-rw-r--r-- | src/afl-fuzz-init.c | 18 | ||||
-rw-r--r-- | src/afl-fuzz-stats.c | 6 | ||||
-rw-r--r-- | src/afl-fuzz.c | 34 | ||||
-rw-r--r-- | src/afl-showmap.c | 12 | ||||
-rw-r--r-- | src/afl-tmin.c | 12 |
11 files changed, 66 insertions, 50 deletions
diff --git a/include/common.h b/include/common.h index ea607886..ad1f81fb 100644 --- a/include/common.h +++ b/include/common.h @@ -34,5 +34,6 @@ void check_environment_vars(char** env); char** get_qemu_argv(u8* own_loc, char** argv, int argc); char** get_wine_argv(u8* own_loc, char** argv, int argc); +char* get_afl_env(char* env); #endif diff --git a/src/afl-analyze.c b/src/afl-analyze.c index bee78519..94c055a6 100644 --- a/src/afl-analyze.c +++ b/src/afl-analyze.c @@ -77,7 +77,7 @@ static s32 dev_null_fd = -1; /* FD to /dev/null */ u8 edges_only, /* Ignore hit counts? */ use_hex_offsets, /* Show hex offsets? */ - use_stdin = 1; /* Use stdin for program input? */ + be_quiet, use_stdin = 1; /* Use stdin for program input? */ static volatile u8 stop_soon, /* Ctrl-C pressed? */ child_timed_out; /* Child timed out? */ @@ -660,7 +660,7 @@ static void set_up_environment(void) { if (access(use_dir, R_OK | W_OK | X_OK)) { - use_dir = getenv("TMPDIR"); + use_dir = get_afl_env("TMPDIR"); if (!use_dir) use_dir = "/tmp"; } @@ -671,7 +671,7 @@ static void set_up_environment(void) { /* Set sane defaults... */ - x = getenv("ASAN_OPTIONS"); + x = get_afl_env("ASAN_OPTIONS"); if (x) { @@ -683,7 +683,7 @@ static void set_up_environment(void) { } - x = getenv("MSAN_OPTIONS"); + x = get_afl_env("MSAN_OPTIONS"); if (x) { @@ -709,7 +709,7 @@ static void set_up_environment(void) { "allocator_may_return_null=1:" "msan_track_origins=0", 0); - if (getenv("AFL_PRELOAD")) { + if (get_afl_env("AFL_PRELOAD")) { if (qemu_mode) { @@ -995,7 +995,7 @@ int main(int argc, char** argv, char** envp) { if (optind == argc || !in_file) usage(argv[0]); - use_hex_offsets = !!getenv("AFL_ANALYZE_HEX"); + use_hex_offsets = !!get_afl_env("AFL_ANALYZE_HEX"); check_environment_vars(envp); setup_shm(0); @@ -1030,7 +1030,7 @@ int main(int argc, char** argv, char** envp) { if (child_timed_out) FATAL("Target binary times out (adjusting -t may help)."); - if (getenv("AFL_SKIP_BIN_CHECK") == NULL && !anything_set()) + if (get_afl_env("AFL_SKIP_BIN_CHECK") == NULL && !anything_set()) FATAL("No instrumentation detected."); analyze(use_argv); diff --git a/src/afl-common.c b/src/afl-common.c index 0f8094be..46d7de26 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -38,6 +38,7 @@ u8* target_path; /* Path to target binary */ extern u8 use_stdin; +extern u8 be_quiet; void detect_file_args(char** argv, u8* prog_in) { @@ -313,3 +314,15 @@ void check_environment_vars(char** envp) { } +char* get_afl_env(char* env) { + + char* val; + + if ((val = getenv(env)) != NULL) + if (!be_quiet) + OKF("Loaded environment variable %s with value %s\n", env, val); + + return val; + +} + diff --git a/src/afl-forkserver.c b/src/afl-forkserver.c index ce809532..bec31c65 100644 --- a/src/afl-forkserver.c +++ b/src/afl-forkserver.c @@ -27,6 +27,7 @@ #include "config.h" #include "types.h" #include "debug.h" +#include "common.h" #include "forkserver.h" #include <stdio.h> @@ -206,7 +207,7 @@ void init_forkserver(char **argv) { setsid(); - if (!getenv("AFL_DEBUG_CHILD_OUTPUT")) { + if (!get_afl_env("AFL_DEBUG_CHILD_OUTPUT")) { dup2(dev_null_fd, 1); dup2(dev_null_fd, 2); diff --git a/src/afl-fuzz-cmplog.c b/src/afl-fuzz-cmplog.c index 3d34bf71..ec4d2ecc 100644 --- a/src/afl-fuzz-cmplog.c +++ b/src/afl-fuzz-cmplog.c @@ -88,7 +88,7 @@ void init_cmplog_forkserver(char** argv) { setsid(); - if (!getenv("AFL_DEBUG_CHILD_OUTPUT")) { + if (!get_afl_env("AFL_DEBUG_CHILD_OUTPUT")) { dup2(dev_null_fd, 1); dup2(dev_null_fd, 2); diff --git a/src/afl-fuzz-globals.c b/src/afl-fuzz-globals.c index d5d70542..fc71d29d 100644 --- a/src/afl-fuzz-globals.c +++ b/src/afl-fuzz-globals.c @@ -87,6 +87,7 @@ u8 cal_cycles = CAL_CYCLES, /* Calibration cycles defaults */ debug, /* Debug mode */ no_unlink, /* do not unlink cur_input */ use_stdin = 1, /* use stdin for sending data */ + be_quiet, /* is AFL_QUIET set? */ custom_only, /* Custom mutator only mode */ python_only; /* Python-only mode */ diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c index 15dd4d14..632cdf6b 100644 --- a/src/afl-fuzz-init.c +++ b/src/afl-fuzz-init.c @@ -275,7 +275,7 @@ cpuset_destroy(c); void setup_post(void) { void* dh; - u8* fn = getenv("AFL_POST_LIBRARY"); + u8* fn = get_afl_env("AFL_POST_LIBRARY"); u32 tlen = 6; if (!fn) return; @@ -476,7 +476,7 @@ void perform_dry_run(char** argv) { struct queue_entry* q = queue; u32 cal_failures = 0; - u8* skip_crashes = getenv("AFL_SKIP_CRASHES"); + u8* skip_crashes = get_afl_env("AFL_SKIP_CRASHES"); while (q) { @@ -1499,7 +1499,7 @@ void check_crash_handling(void) { " sudo launchctl unload -w ${SL}/LaunchDaemons/${PL}.Root.plist\n"); #endif - if (!getenv("AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES")) + if (!get_afl_env("AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES")) FATAL("Crash reporter detected"); #else @@ -1551,7 +1551,7 @@ void check_cpu_governor(void) { u8 tmp[128]; u64 min = 0, max = 0; - if (getenv("AFL_SKIP_CPUFREQ")) return; + if (get_afl_env("AFL_SKIP_CPUFREQ")) return; if (cpu_aff > 0) snprintf(tmp, sizeof(tmp), "%s%d%s", "/sys/devices/system/cpu/cpu", cpu_aff, @@ -1632,7 +1632,7 @@ void check_cpu_governor(void) { #elif defined __APPLE__ u64 min = 0, max = 0; size_t mlen = sizeof(min); - if (getenv("AFL_SKIP_CPUFREQ")) return; + if (get_afl_env("AFL_SKIP_CPUFREQ")) return; ACTF("Checking CPU scaling governor..."); @@ -1805,7 +1805,7 @@ static void handle_resize(int sig) { void check_asan_opts(void) { - u8* x = getenv("ASAN_OPTIONS"); + u8* x = get_afl_env("ASAN_OPTIONS"); if (x) { @@ -1817,7 +1817,7 @@ void check_asan_opts(void) { } - x = getenv("MSAN_OPTIONS"); + x = get_afl_env("MSAN_OPTIONS"); if (x) { @@ -1913,7 +1913,7 @@ void check_binary(u8* fname) { } - if (getenv("AFL_SKIP_BIN_CHECK") || use_wine) return; + if (get_afl_env("AFL_SKIP_BIN_CHECK") || use_wine) return; /* Check for blatant user errors. */ @@ -2082,7 +2082,7 @@ void check_if_tty(void) { struct winsize ws; - if (getenv("AFL_NO_UI")) { + if (get_afl_env("AFL_NO_UI")) { OKF("Disabling the UI because AFL_NO_UI is set."); not_on_tty = 1; diff --git a/src/afl-fuzz-stats.c b/src/afl-fuzz-stats.c index 344e0abf..c1aa8315 100644 --- a/src/afl-fuzz-stats.c +++ b/src/afl-fuzz-stats.c @@ -267,10 +267,10 @@ void show_stats(void) { /* Honor AFL_EXIT_WHEN_DONE and AFL_BENCH_UNTIL_CRASH. */ if (!dumb_mode && cycles_wo_finds > 100 && !pending_not_fuzzed && - getenv("AFL_EXIT_WHEN_DONE")) + get_afl_env("AFL_EXIT_WHEN_DONE")) stop_soon = 2; - if (total_crashes && getenv("AFL_BENCH_UNTIL_CRASH")) stop_soon = 2; + if (total_crashes && get_afl_env("AFL_BENCH_UNTIL_CRASH")) stop_soon = 2; /* If we're not on TTY, bail out. */ @@ -829,7 +829,7 @@ void show_init_stats(void) { /* In dumb mode, re-running every timing out test case with a generous time limit is very expensive, so let's select a more conservative default. */ - if (dumb_mode && !getenv("AFL_HANG_TMOUT")) + if (dumb_mode && !get_afl_env("AFL_HANG_TMOUT")) hang_tmout = MIN(EXEC_TIMEOUT, exec_tmout * 2 + 100); OKF("All set and ready to roll!"); diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index 6b80e066..c7f8ccad 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -228,7 +228,7 @@ int main(int argc, char** argv, char** envp) { u32 sync_interval_cnt = 0, seek_to, show_help = 0; u8* extras_dir = 0; u8 mem_limit_given = 0; - u8 exit_1 = !!getenv("AFL_BENCH_JUST_ONE"); + u8 exit_1 = !!get_afl_env("AFL_BENCH_JUST_ONE"); char** use_argv; struct timeval tv; @@ -461,7 +461,7 @@ int main(int argc, char** argv, char** envp) { case 'n': /* dumb mode */ if (dumb_mode) FATAL("Multiple -n options not supported"); - if (getenv("AFL_DUMB_FORKSRV")) + if (get_afl_env("AFL_DUMB_FORKSRV")) dumb_mode = 2; else dumb_mode = 1; @@ -715,7 +715,7 @@ int main(int argc, char** argv, char** envp) { } - if (getenv("AFL_DISABLE_TRIM")) disable_trim = 1; + if (get_afl_env("AFL_DISABLE_TRIM")) disable_trim = 1; if (getenv("AFL_NO_UI") && getenv("AFL_FORCE_UI")) FATAL("AFL_NO_UI and AFL_FORCE_UI are mutually exclusive"); @@ -744,13 +744,13 @@ int main(int argc, char** argv, char** envp) { } - if (getenv("AFL_NO_FORKSRV")) no_forkserver = 1; - if (getenv("AFL_NO_CPU_RED")) no_cpu_meter_red = 1; - if (getenv("AFL_NO_ARITH")) no_arith = 1; - if (getenv("AFL_SHUFFLE_QUEUE")) shuffle_queue = 1; - if (getenv("AFL_FAST_CAL")) fast_cal = 1; + if (get_afl_env("AFL_NO_FORKSRV")) no_forkserver = 1; + if (get_afl_env("AFL_NO_CPU_RED")) no_cpu_meter_red = 1; + if (get_afl_env("AFL_NO_ARITH")) no_arith = 1; + if (get_afl_env("AFL_SHUFFLE_QUEUE")) shuffle_queue = 1; + if (get_afl_env("AFL_FAST_CAL")) fast_cal = 1; - if (getenv("AFL_HANG_TMOUT")) { + if (get_afl_env("AFL_HANG_TMOUT")) { hang_tmout = atoi(getenv("AFL_HANG_TMOUT")); if (!hang_tmout) FATAL("Invalid value of AFL_HANG_TMOUT"); @@ -765,7 +765,7 @@ int main(int argc, char** argv, char** envp) { "LD_PRELOAD is set, are you sure that is what to you want to do " "instead of using AFL_PRELOAD?"); - if (getenv("AFL_PRELOAD")) { + if (get_afl_env("AFL_PRELOAD")) { if (qemu_mode) { @@ -811,9 +811,9 @@ int main(int argc, char** argv, char** envp) { fix_up_banner(argv[optind]); check_if_tty(); - if (getenv("AFL_FORCE_UI")) not_on_tty = 0; + if (get_afl_env("AFL_FORCE_UI")) not_on_tty = 0; - if (getenv("AFL_CAL_FAST")) { + if (get_afl_env("AFL_CAL_FAST")) { /* Use less calibration cycles, for slow applications */ cal_cycles = 3; @@ -821,9 +821,9 @@ int main(int argc, char** argv, char** envp) { } - if (getenv("AFL_DEBUG")) debug = 1; + if (get_afl_env("AFL_DEBUG")) debug = 1; - if (getenv("AFL_PYTHON_ONLY")) { + if (get_afl_env("AFL_PYTHON_ONLY")) { /* This ensures we don't proceed to havoc/splice */ python_only = 1; @@ -833,7 +833,7 @@ int main(int argc, char** argv, char** envp) { } - if (getenv("AFL_CUSTOM_MUTATOR_ONLY")) { + if (get_afl_env("AFL_CUSTOM_MUTATOR_ONLY")) { /* This ensures we don't proceed to havoc/splice */ custom_only = 1; @@ -882,7 +882,7 @@ int main(int argc, char** argv, char** envp) { if (!timeout_given) find_timeout(); - if ((tmp_dir = getenv("AFL_TMPDIR")) != NULL && !in_place_resume) { + if ((tmp_dir = get_afl_env("AFL_TMPDIR")) != NULL && !in_place_resume) { char tmpfile[file_extension ? strlen(tmp_dir) + 1 + 10 + 1 + strlen(file_extension) + 1 @@ -1046,7 +1046,7 @@ int main(int argc, char** argv, char** envp) { prev_queued = queued_paths; - if (sync_id && queue_cycle == 1 && getenv("AFL_IMPORT_FIRST")) + if (sync_id && queue_cycle == 1 && get_afl_env("AFL_IMPORT_FIRST")) sync_fuzzers(use_argv); } diff --git a/src/afl-showmap.c b/src/afl-showmap.c index d6ac1e7d..4c1168a6 100644 --- a/src/afl-showmap.c +++ b/src/afl-showmap.c @@ -72,7 +72,7 @@ s32 dev_null_fd = -1; /* FD to /dev/null */ s32 out_fd = -1, out_dir_fd = -1, dev_urandom_fd = -1; FILE* plot_file; -u8 uses_asan; +u8 uses_asan, be_quiet; u8* trace_bits; /* SHM with instrumentation bitmap */ @@ -173,8 +173,8 @@ static u32 write_results_to_file(u8* out_file) { s32 fd; u32 i, ret = 0; - u8 cco = !!getenv("AFL_CMIN_CRASHES_ONLY"), - caa = !!getenv("AFL_CMIN_ALLOW_ANY"); + u8 cco = !!get_afl_env("AFL_CMIN_CRASHES_ONLY"), + caa = !!get_afl_env("AFL_CMIN_ALLOW_ANY"); if (!strncmp(out_file, "/dev/", 5)) { @@ -541,7 +541,7 @@ static void set_up_environment(void) { "allocator_may_return_null=1:" "msan_track_origins=0", 0); - if (getenv("AFL_PRELOAD")) { + if (get_afl_env("AFL_PRELOAD")) { if (qemu_mode) { @@ -955,7 +955,7 @@ int main(int argc, char** argv, char** envp) { if (access(use_dir, R_OK | W_OK | X_OK)) { - use_dir = getenv("TMPDIR"); + use_dir = get_afl_env("TMPDIR"); if (!use_dir) use_dir = "/tmp"; } @@ -968,7 +968,7 @@ int main(int argc, char** argv, char** envp) { if (arg_offset) argv[arg_offset] = stdin_file; - if (getenv("AFL_DEBUG")) { + if (get_afl_env("AFL_DEBUG")) { int i = optind; SAYF(cMGN "[D]" cRST " %s:", target_path); diff --git a/src/afl-tmin.c b/src/afl-tmin.c index f6878903..13fdbee7 100644 --- a/src/afl-tmin.c +++ b/src/afl-tmin.c @@ -92,7 +92,7 @@ u8 crash_mode, /* Crash-centric mode? */ exit_crash, /* Treat non-zero exit as crash? */ edges_only, /* Ignore hit counts? */ exact_mode, /* Require path match for crashes? */ - use_stdin = 1; /* Use stdin for program input? */ + be_quiet, use_stdin = 1; /* Use stdin for program input? */ static volatile u8 stop_soon; /* Ctrl-C pressed? */ @@ -829,7 +829,7 @@ static void set_up_environment(void) { if (access(use_dir, R_OK | W_OK | X_OK)) { - use_dir = getenv("TMPDIR"); + use_dir = get_afl_env("TMPDIR"); if (!use_dir) use_dir = "/tmp"; } @@ -846,7 +846,7 @@ static void set_up_environment(void) { /* Set sane defaults... */ - x = getenv("ASAN_OPTIONS"); + x = get_afl_env("ASAN_OPTIONS"); if (x) { @@ -858,7 +858,7 @@ static void set_up_environment(void) { } - x = getenv("MSAN_OPTIONS"); + x = get_afl_env("MSAN_OPTIONS"); if (x) { @@ -884,7 +884,7 @@ static void set_up_environment(void) { "allocator_may_return_null=1:" "msan_track_origins=0", 0); - if (getenv("AFL_PRELOAD")) { + if (get_afl_env("AFL_PRELOAD")) { if (qemu_mode) { @@ -1240,7 +1240,7 @@ int main(int argc, char** argv, char** envp) { use_argv = argv + optind; - exact_mode = !!getenv("AFL_TMIN_EXACT"); + exact_mode = !!get_afl_env("AFL_TMIN_EXACT"); SAYF("\n"); |