afl-gcc and afl-clang: fail when binary name can't be used to determine build mode

This is a continuation of PR #318.
The goal is to prevent issues where binaries with the wrong name will
silently pass control to the C compiler instead of failing.
This makes it more explicit that aflplusplus relies on the name of the
binary for correct compiler execution.
This commit is contained in:
Rick van Schijndel
2020-04-23 23:16:13 +02:00
parent b6f9f4c436
commit 82b6b8c87e
2 changed files with 29 additions and 6 deletions

View File

@ -123,11 +123,17 @@ static void edit_params(u32 argc, char **argv) {
u8 *alt_cxx = getenv("AFL_CXX"); u8 *alt_cxx = getenv("AFL_CXX");
cc_params[0] = alt_cxx && *alt_cxx ? alt_cxx : (u8 *)AFL_GCC_CXX; cc_params[0] = alt_cxx && *alt_cxx ? alt_cxx : (u8 *)AFL_GCC_CXX;
} else { } else if (!strcmp(name, "afl-gcc-fast")) {
u8 *alt_cc = getenv("AFL_CC"); u8 *alt_cc = getenv("AFL_CC");
cc_params[0] = alt_cc && *alt_cc ? alt_cc : (u8 *)AFL_GCC_CC; cc_params[0] = alt_cc && *alt_cc ? alt_cc : (u8 *)AFL_GCC_CC;
} else {
fprintf(stderr, "Name of the binary: %s\n", argv[0]);
FATAL(
"Name of the binary is not a known name, expected afl-(gcc|g++)-fast");
} }
char *fplugin_arg = alloc_printf("-fplugin=%s/afl-gcc-pass.so", obj_path); char *fplugin_arg = alloc_printf("-fplugin=%s/afl-gcc-pass.so", obj_path);

View File

@ -149,11 +149,17 @@ static void edit_params(u32 argc, char **argv) {
u8 *alt_cxx = getenv("AFL_CXX"); u8 *alt_cxx = getenv("AFL_CXX");
cc_params[0] = alt_cxx && *alt_cxx ? alt_cxx : (u8 *)"clang++"; cc_params[0] = alt_cxx && *alt_cxx ? alt_cxx : (u8 *)"clang++";
} else { } else if (!strcmp(name, "afl-clang")) {
u8 *alt_cc = getenv("AFL_CC"); u8 *alt_cc = getenv("AFL_CC");
cc_params[0] = alt_cc && *alt_cc ? alt_cc : (u8 *)"clang"; cc_params[0] = alt_cc && *alt_cc ? alt_cc : (u8 *)"clang";
} else {
fprintf(stderr, "Name of the binary: %s\n", argv[0]);
FATAL(
"Name of the binary is not a known name, expected afl-clang(++)");
} }
} else { } else {
@ -166,12 +172,17 @@ static void edit_params(u32 argc, char **argv) {
#ifdef __APPLE__ #ifdef __APPLE__
if (!strcmp(name, "afl-g++")) if (!strcmp(name, "afl-g++")) {
cc_params[0] = getenv("AFL_CXX"); cc_params[0] = getenv("AFL_CXX");
else if (!strcmp(name, "afl-gcj")) } else if (!strcmp(name, "afl-gcj")) {
cc_params[0] = getenv("AFL_GCJ"); cc_params[0] = getenv("AFL_GCJ");
else } else if (!strcmp(name, "afl-gcc")) {
cc_params[0] = getenv("AFL_CC"); cc_params[0] = getenv("AFL_CC");
} else {
fprintf(stderr, "Name of the binary: %s\n", argv[0]);
FATAL(
"Name of the binary is not a known name, expected afl-gcc/g++/gcj");
}
if (!cc_params[0]) { if (!cc_params[0]) {
@ -199,11 +210,17 @@ static void edit_params(u32 argc, char **argv) {
u8 *alt_cc = getenv("AFL_GCJ"); u8 *alt_cc = getenv("AFL_GCJ");
cc_params[0] = alt_cc && *alt_cc ? alt_cc : (u8 *)"gcj"; cc_params[0] = alt_cc && *alt_cc ? alt_cc : (u8 *)"gcj";
} else { } else if (!strcmp(name, "afl-gcc")) {
u8 *alt_cc = getenv("AFL_CC"); u8 *alt_cc = getenv("AFL_CC");
cc_params[0] = alt_cc && *alt_cc ? alt_cc : (u8 *)"gcc"; cc_params[0] = alt_cc && *alt_cc ? alt_cc : (u8 *)"gcc";
} else {
fprintf(stderr, "Name of the binary: %s\n", argv[0]);
FATAL(
"Name of the binary is not a known name, expected afl-gcc/g++/gcj");
} }
#endif /* __APPLE__ */ #endif /* __APPLE__ */