honor no_quiet for missing llvm_mode output, also print to stderr with afl-*-rt.o.c instead of stdout for errors plus two potential bad free() fixes
diff --git a/gcc_plugin/Makefile b/gcc_plugin/Makefile
index 98ddffd..c5aa661 100644
--- a/gcc_plugin/Makefile
+++ b/gcc_plugin/Makefile
@@ -30,6 +30,7 @@
CFLAGS += -Wall -I../include -D_FORTIFY_SOURCE=2 -Wno-pointer-sign \
-DAFL_PATH=\"$(HELPER_PATH)\" -DBIN_PATH=\"$(BIN_PATH)\" \
-DGCC_VERSION=\"$(GCCVER)\" -DGCC_BINDIR=\"$(GCCBINDIR)\" \
+ -Wno-unused-function
CXXFLAGS ?= -O3 -g -funroll-loops
CXXEFLAGS := $(CXXFLAGS) -Wall -D_FORTIFY_SOURCE=2
diff --git a/gcc_plugin/afl-gcc-fast.c b/gcc_plugin/afl-gcc-fast.c
index a57f48d..8de92cb 100644
--- a/gcc_plugin/afl-gcc-fast.c
+++ b/gcc_plugin/afl-gcc-fast.c
@@ -361,7 +361,9 @@
}
- }
+ } else
+
+ be_quiet = 1;
check_environment_vars(envp);
diff --git a/gcc_plugin/afl-gcc-rt.o.c b/gcc_plugin/afl-gcc-rt.o.c
index 508d444..77bb532 100644
--- a/gcc_plugin/afl-gcc-rt.o.c
+++ b/gcc_plugin/afl-gcc-rt.o.c
@@ -94,7 +94,7 @@
shm_fd = shm_open(shm_file_path, O_RDWR, 0600);
if (shm_fd == -1) {
- printf("shm_open() failed\n");
+ fprintf(stderr, "shm_open() failed\n");
exit(1);
}
@@ -106,7 +106,7 @@
close(shm_fd);
shm_fd = -1;
- printf("mmap() failed\n");
+ fprintf(stderr, "mmap() failed\n");
exit(2);
}
diff --git a/llvm_mode/LLVMInsTrim.so.cc b/llvm_mode/LLVMInsTrim.so.cc
index 390e069..8127c89 100644
--- a/llvm_mode/LLVMInsTrim.so.cc
+++ b/llvm_mode/LLVMInsTrim.so.cc
@@ -142,7 +142,7 @@
#if LLVM_VERSION_MAJOR < 9
char *neverZero_counters_str;
if ((neverZero_counters_str = getenv("AFL_LLVM_NOT_ZERO")) != NULL)
- OKF("LLVM neverZero activated (by hexcoder)\n");
+ if (!be_quiet) OKF("LLVM neverZero activated (by hexcoder)\n");
#endif
if (getenv("AFL_LLVM_INSTRIM_LOOPHEAD") != NULL ||
@@ -523,15 +523,19 @@
}
- char modeline[100];
- snprintf(modeline, sizeof(modeline), "%s%s%s%s",
- getenv("AFL_HARDEN") ? "hardened" : "non-hardened",
- getenv("AFL_USE_ASAN") ? ", ASAN" : "",
- getenv("AFL_USE_MSAN") ? ", MSAN" : "",
- getenv("AFL_USE_UBSAN") ? ", UBSAN" : "");
+ if (!be_quiet) {
- OKF("Instrumented %u locations (%llu, %llu) (%s mode)\n", total_instr,
- total_rs, total_hs, modeline);
+ char modeline[100];
+ snprintf(modeline, sizeof(modeline), "%s%s%s%s",
+ getenv("AFL_HARDEN") ? "hardened" : "non-hardened",
+ getenv("AFL_USE_ASAN") ? ", ASAN" : "",
+ getenv("AFL_USE_MSAN") ? ", MSAN" : "",
+ getenv("AFL_USE_UBSAN") ? ", UBSAN" : "");
+
+ OKF("Instrumented %u locations (%llu, %llu) (%s mode)\n", total_instr,
+ total_rs, total_hs, modeline);
+
+ }
return false;
diff --git a/llvm_mode/afl-ld.c b/llvm_mode/afl-ld.c
index 0e85795..bd451ca 100644
--- a/llvm_mode/afl-ld.c
+++ b/llvm_mode/afl-ld.c
@@ -424,7 +424,7 @@
} else
- if (dir_ent->d_name[0] != '.')
+ if (dir_ent->d_name[0] != '.' && !be_quiet)
WARNF("Unusual file found in ar archive %s: %s", argv[i], ar_file);
}
diff --git a/llvm_mode/afl-llvm-lto-instrumentation.so.cc b/llvm_mode/afl-llvm-lto-instrumentation.so.cc
index d322470..febb895 100644
--- a/llvm_mode/afl-llvm-lto-instrumentation.so.cc
+++ b/llvm_mode/afl-llvm-lto-instrumentation.so.cc
@@ -282,7 +282,7 @@
if (!newBB) {
- WARNF("Split failed!");
+ if (!be_quiet) WARNF("Split failed!");
continue;
}
diff --git a/llvm_mode/afl-llvm-lto-whitelist.so.cc b/llvm_mode/afl-llvm-lto-whitelist.so.cc
index 617f9ca..48df76c 100644
--- a/llvm_mode/afl-llvm-lto-whitelist.so.cc
+++ b/llvm_mode/afl-llvm-lto-whitelist.so.cc
@@ -217,6 +217,7 @@
F.getName().compare("init") == 0 ||
F.getName().compare("_init") == 0) {
+ // We do not honor be_quiet for this one
WARNF("Cannot ignore functions main/init/start");
} else {
diff --git a/llvm_mode/afl-llvm-rt.o.c b/llvm_mode/afl-llvm-rt.o.c
index 64c2ff2..58b6467 100644
--- a/llvm_mode/afl-llvm-rt.o.c
+++ b/llvm_mode/afl-llvm-rt.o.c
@@ -97,7 +97,7 @@
shm_fd = shm_open(shm_file_path, O_RDWR, 0600);
if (shm_fd == -1) {
- printf("shm_open() failed\n");
+ fprintf(stderr, "shm_open() failed\n");
exit(1);
}
@@ -109,7 +109,7 @@
close(shm_fd);
shm_fd = -1;
- printf("mmap() failed\n");
+ fprintf(stderr, "mmap() failed\n");
exit(2);
}
@@ -145,7 +145,7 @@
shm_fd = shm_open(shm_file_path, O_RDWR, 0600);
if (shm_fd == -1) {
- printf("shm_open() failed\n");
+ fprintf(stderr, "shm_open() failed\n");
exit(1);
}
@@ -158,7 +158,7 @@
close(shm_fd);
shm_fd = -1;
- printf("mmap() failed\n");
+ fprintf(stderr, "mmap() failed\n");
exit(2);
}
diff --git a/src/afl-common.c b/src/afl-common.c
index 20fc424..9d6e52b 100644
--- a/src/afl-common.c
+++ b/src/afl-common.c
@@ -111,7 +111,7 @@
char** get_qemu_argv(u8* own_loc, char** argv, int argc) {
char** new_argv = ck_alloc(sizeof(char*) * (argc + 4));
- u8 * tmp, *cp, *rsl, *own_copy;
+ u8 * tmp, *cp = NULL, *rsl, *own_copy;
memcpy(new_argv + 3, argv + 1, (int)(sizeof(char*)) * argc);
@@ -156,7 +156,7 @@
if (!access(BIN_PATH "/afl-qemu-trace", X_OK)) {
- ck_free(cp);
+ if (cp != NULL) ck_free(cp);
target_path = new_argv[0] = ck_strdup(BIN_PATH "/afl-qemu-trace");
return new_argv;
@@ -187,7 +187,7 @@
char** get_wine_argv(u8* own_loc, char** argv, int argc) {
char** new_argv = ck_alloc(sizeof(char*) * (argc + 3));
- u8 * tmp, *cp, *rsl, *own_copy;
+ u8 * tmp, *cp = NULL, *rsl, *own_copy;
memcpy(new_argv + 2, argv + 1, (int)(sizeof(char*)) * argc);
@@ -226,7 +226,7 @@
if (!access(cp, X_OK)) {
- ck_free(cp);
+ if (cp != NULL) ck_free(cp);
cp = alloc_printf("%s/afl-wine-trace", own_copy);