aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhexcoder <hexcoder-@users.noreply.github.com>2021-03-17 08:00:32 +0100
committerGitHub <noreply@github.com>2021-03-17 08:00:32 +0100
commitd17abce59b846d2008eac3dd1a73939e91f4b653 (patch)
treee2715f85ccae8a64a0bce669a7a767dea363f673 /src
parent62f067ec71aff384a197511b33142002ca284c66 (diff)
parentb715050de9846ab4b1f30a811af83b7a4b9e09a3 (diff)
downloadafl++-d17abce59b846d2008eac3dd1a73939e91f4b653.tar.gz
Merge branch 'dev' into atat-plusplus
Diffstat (limited to 'src')
-rw-r--r--src/afl-analyze.c58
-rw-r--r--src/afl-cc.c65
-rw-r--r--src/afl-common.c69
-rw-r--r--src/afl-fuzz-init.c1
-rw-r--r--src/afl-fuzz-queue.c2
-rw-r--r--src/afl-fuzz.c75
-rw-r--r--src/afl-showmap.c58
-rw-r--r--src/afl-tmin.c58
8 files changed, 57 insertions, 329 deletions
diff --git a/src/afl-analyze.c b/src/afl-analyze.c
index d46ecb8d..86b0f7e9 100644
--- a/src/afl-analyze.c
+++ b/src/afl-analyze.c
@@ -822,38 +822,7 @@ static void set_up_environment(void) {
if (qemu_mode) {
- u8 *qemu_preload = getenv("QEMU_SET_ENV");
- u8 *afl_preload = getenv("AFL_PRELOAD");
- u8 *buf;
-
- s32 i, afl_preload_size = strlen(afl_preload);
- for (i = 0; i < afl_preload_size; ++i) {
-
- if (afl_preload[i] == ',') {
-
- PFATAL(
- "Comma (',') is not allowed in AFL_PRELOAD when -Q is "
- "specified!");
-
- }
-
- }
-
- if (qemu_preload) {
-
- buf = alloc_printf("%s,LD_PRELOAD=%s,DYLD_INSERT_LIBRARIES=%s",
- qemu_preload, afl_preload, afl_preload);
-
- } else {
-
- buf = alloc_printf("LD_PRELOAD=%s,DYLD_INSERT_LIBRARIES=%s",
- afl_preload, afl_preload);
-
- }
-
- setenv("QEMU_SET_ENV", buf, 1);
-
- ck_free(buf);
+ /* afl-qemu-trace takes care of converting AFL_PRELOAD. */
} else {
@@ -1079,31 +1048,6 @@ int main(int argc, char **argv_orig, char **envp) {
if (optind == argc || !in_file) { usage(argv[0]); }
- if (qemu_mode && getenv("AFL_USE_QASAN")) {
-
- u8 *preload = getenv("AFL_PRELOAD");
- u8 *libqasan = get_libqasan_path(argv_orig[0]);
-
- if (!preload) {
-
- setenv("AFL_PRELOAD", libqasan, 0);
-
- } else {
-
- u8 *result = ck_alloc(strlen(libqasan) + strlen(preload) + 2);
- strcpy(result, libqasan);
- strcat(result, " ");
- strcat(result, preload);
-
- setenv("AFL_PRELOAD", result, 1);
- ck_free(result);
-
- }
-
- ck_free(libqasan);
-
- }
-
map_size = get_map_size();
use_hex_offsets = !!get_afl_env("AFL_ANALYZE_HEX");
diff --git a/src/afl-cc.c b/src/afl-cc.c
index 44654de0..206066fd 100644
--- a/src/afl-cc.c
+++ b/src/afl-cc.c
@@ -959,62 +959,65 @@ static void edit_params(u32 argc, char **argv, char **envp) {
if (compiler_mode != GCC && compiler_mode != CLANG) {
- switch (bit_mode) {
+ switch (bit_mode) {
- case 0:
- cc_params[cc_par_cnt++] =
- alloc_printf("%s/afl-compiler-rt.o", obj_path);
- if (lto_mode)
+ case 0:
+ if (!shared_linking)
cc_params[cc_par_cnt++] =
- alloc_printf("%s/afl-llvm-rt-lto.o", obj_path);
- break;
-
- case 32:
- cc_params[cc_par_cnt++] =
- alloc_printf("%s/afl-compiler-rt-32.o", obj_path);
- if (access(cc_params[cc_par_cnt - 1], R_OK))
- FATAL("-m32 is not supported by your compiler");
- if (lto_mode) {
-
+ alloc_printf("%s/afl-compiler-rt.o", obj_path);
+ if (lto_mode)
+ cc_params[cc_par_cnt++] =
+ alloc_printf("%s/afl-llvm-rt-lto.o", obj_path);
+ break;
+
+ case 32:
+ if (!shared_linking)
cc_params[cc_par_cnt++] =
- alloc_printf("%s/afl-llvm-rt-lto-32.o", obj_path);
+ alloc_printf("%s/afl-compiler-rt-32.o", obj_path);
if (access(cc_params[cc_par_cnt - 1], R_OK))
FATAL("-m32 is not supported by your compiler");
+ if (lto_mode) {
- }
+ cc_params[cc_par_cnt++] =
+ alloc_printf("%s/afl-llvm-rt-lto-32.o", obj_path);
+ if (access(cc_params[cc_par_cnt - 1], R_OK))
+ FATAL("-m32 is not supported by your compiler");
- break;
+ }
- case 64:
- cc_params[cc_par_cnt++] =
- alloc_printf("%s/afl-compiler-rt-64.o", obj_path);
- if (access(cc_params[cc_par_cnt - 1], R_OK))
- FATAL("-m64 is not supported by your compiler");
- if (lto_mode) {
+ break;
+ case 64:
+ if (!shared_linking)
cc_params[cc_par_cnt++] =
- alloc_printf("%s/afl-llvm-rt-lto-64.o", obj_path);
+ alloc_printf("%s/afl-compiler-rt-64.o", obj_path);
if (access(cc_params[cc_par_cnt - 1], R_OK))
FATAL("-m64 is not supported by your compiler");
+ if (lto_mode) {
- }
+ cc_params[cc_par_cnt++] =
+ alloc_printf("%s/afl-llvm-rt-lto-64.o", obj_path);
+ if (access(cc_params[cc_par_cnt - 1], R_OK))
+ FATAL("-m64 is not supported by your compiler");
- break;
+ }
- }
+ break;
+
+ }
#if !defined(__APPLE__) && !defined(__sun)
- if (!shared_linking)
+ if (!shared_linking)
cc_params[cc_par_cnt++] =
alloc_printf("-Wl,--dynamic-list=%s/dynamic_list.txt", obj_path);
#endif
+ }
+
#if defined(USEMMAP) && !defined(__HAIKU__)
cc_params[cc_par_cnt++] = "-lrt";
#endif
- }
-
#endif
cc_params[cc_par_cnt] = NULL;
diff --git a/src/afl-common.c b/src/afl-common.c
index 55564554..b36eaa4a 100644
--- a/src/afl-common.c
+++ b/src/afl-common.c
@@ -144,6 +144,15 @@ void argv_cpy_free(char **argv) {
char **get_qemu_argv(u8 *own_loc, u8 **target_path_p, int argc, char **argv) {
+ if (unlikely(getenv("AFL_QEMU_CUSTOM_BIN"))) {
+
+ WARNF(
+ "AFL_QEMU_CUSTOM_BIN is enabled. "
+ "You must run your target under afl-qemu-trace on your own!");
+ return argv;
+
+ }
+
if (!unlikely(own_loc)) { FATAL("BUG: param own_loc is NULL"); }
u8 *tmp, *cp = NULL, *rsl, *own_copy;
@@ -333,66 +342,6 @@ char **get_wine_argv(u8 *own_loc, u8 **target_path_p, int argc, char **argv) {
}
-/* Get libqasan path. */
-
-u8 *get_libqasan_path(u8 *own_loc) {
-
- if (!unlikely(own_loc)) { FATAL("BUG: param own_loc is NULL"); }
-
- u8 *tmp, *cp = NULL, *rsl, *own_copy;
-
- tmp = getenv("AFL_PATH");
-
- if (tmp) {
-
- cp = alloc_printf("%s/libqasan.so", tmp);
-
- if (access(cp, X_OK)) { FATAL("Unable to find '%s'", tmp); }
-
- return cp;
-
- }
-
- own_copy = ck_strdup(own_loc);
- rsl = strrchr(own_copy, '/');
-
- if (rsl) {
-
- *rsl = 0;
-
- cp = alloc_printf("%s/libqasan.so", own_copy);
- ck_free(own_copy);
-
- if (!access(cp, X_OK)) { return cp; }
-
- } else {
-
- ck_free(own_copy);
-
- }
-
- if (!access(AFL_PATH "/libqasan.so", X_OK)) {
-
- if (cp) { ck_free(cp); }
-
- return ck_strdup(AFL_PATH "/libqasan.so");
-
- }
-
- SAYF("\n" cLRD "[-] " cRST
- "Oops, unable to find the 'libqasan.so' binary. The binary must be "
- "built\n"
- " separately by following the instructions in "
- "qemu_mode/libqasan/README.md. "
- "If you\n"
- " already have the binary installed, you may need to specify "
- "AFL_PATH in the\n"
- " environment.\n");
-
- FATAL("Failed to locate 'libqasan.so'.");
-
-}
-
/* Find binary, used by analyze, showmap, tmin
@returns the path, allocating the string */
diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c
index ca2f75f1..82c1799e 100644
--- a/src/afl-fuzz-init.c
+++ b/src/afl-fuzz-init.c
@@ -2592,6 +2592,7 @@ void check_binary(afl_state_t *afl, u8 *fname) {
}
if (afl->afl_env.afl_skip_bin_check || afl->use_wine || afl->unicorn_mode ||
+ (afl->fsrv.qemu_mode && getenv("AFL_QEMU_CUSTOM_BIN")) ||
afl->non_instrumented_mode) {
return;
diff --git a/src/afl-fuzz-queue.c b/src/afl-fuzz-queue.c
index 835aba40..b2f88205 100644
--- a/src/afl-fuzz-queue.c
+++ b/src/afl-fuzz-queue.c
@@ -325,7 +325,7 @@ static u8 check_if_text(afl_state_t *afl, struct queue_entry *q) {
if (len >= MAX_FILE) len = MAX_FILE - 1;
if ((fd = open(q->fname, O_RDONLY)) < 0) return 0;
- buf = afl_realloc(AFL_BUF_PARAM(in_scratch), len);
+ buf = afl_realloc(AFL_BUF_PARAM(in_scratch), len + 1);
comp = read(fd, buf, len);
close(fd);
if (comp != (ssize_t)len) return 0;
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index ff27048a..2fde561c 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -1022,32 +1022,6 @@ int main(int argc, char **argv_orig, char **envp) {
}
- if (afl->fsrv.qemu_mode && getenv("AFL_USE_QASAN")) {
-
- u8 *preload = getenv("AFL_PRELOAD");
- u8 *libqasan = get_libqasan_path(argv_orig[0]);
-
- if (!preload) {
-
- setenv("AFL_PRELOAD", libqasan, 0);
-
- } else {
-
- u8 *result = ck_alloc(strlen(libqasan) + strlen(preload) + 2);
- strcpy(result, libqasan);
- strcat(result, " ");
- strcat(result, preload);
-
- setenv("AFL_PRELOAD", result, 1);
- ck_free(result);
-
- }
-
- afl->afl_env.afl_preload = (u8 *)getenv("AFL_PRELOAD");
- ck_free(libqasan);
-
- }
-
if (afl->fsrv.mem_limit && afl->shm.cmplog_mode) afl->fsrv.mem_limit += 260;
OKF("afl++ is maintained by Marc \"van Hauser\" Heuse, Heiko \"hexcoder\" "
@@ -1312,38 +1286,7 @@ int main(int argc, char **argv_orig, char **envp) {
if (afl->fsrv.qemu_mode) {
- u8 *qemu_preload = getenv("QEMU_SET_ENV");
- u8 *afl_preload = getenv("AFL_PRELOAD");
- u8 *buf;
-
- s32 j, afl_preload_size = strlen(afl_preload);
- for (j = 0; j < afl_preload_size; ++j) {
-
- if (afl_preload[j] == ',') {
-
- PFATAL(
- "Comma (',') is not allowed in AFL_PRELOAD when -Q is "
- "specified!");
-
- }
-
- }
-
- if (qemu_preload) {
-
- buf = alloc_printf("%s,LD_PRELOAD=%s,DYLD_INSERT_LIBRARIES=%s",
- qemu_preload, afl_preload, afl_preload);
-
- } else {
-
- buf = alloc_printf("LD_PRELOAD=%s,DYLD_INSERT_LIBRARIES=%s",
- afl_preload, afl_preload);
-
- }
-
- setenv("QEMU_SET_ENV", buf, 1);
-
- ck_free(buf);
+ /* afl-qemu-trace takes care of converting AFL_PRELOAD. */
} else {
@@ -1596,9 +1539,9 @@ int main(int argc, char **argv_orig, char **envp) {
&afl->fsrv, afl->argv, &afl->stop_soon, afl->afl_env.afl_debug_child);
// only reinitialize when it makes sense
- if ((map_size < new_map_size ||
+ if ((map_size < new_map_size /*||
(new_map_size != MAP_SIZE && new_map_size < map_size &&
- map_size - new_map_size > MAP_SIZE))) {
+ map_size - new_map_size > MAP_SIZE)*/)) {
OKF("Re-initializing maps to %u bytes", new_map_size);
@@ -1627,8 +1570,6 @@ int main(int argc, char **argv_orig, char **envp) {
}
- afl->fsrv.map_size = map_size;
-
}
if (afl->cmplog_binary) {
@@ -1680,21 +1621,23 @@ int main(int argc, char **argv_orig, char **envp) {
setenv("AFL_NO_AUTODICT", "1", 1); // loaded already
afl->fsrv.trace_bits =
afl_shm_init(&afl->shm, new_map_size, afl->non_instrumented_mode);
+ afl->cmplog_fsrv.trace_bits = afl->fsrv.trace_bits;
afl_fsrv_start(&afl->fsrv, afl->argv, &afl->stop_soon,
afl->afl_env.afl_debug_child);
afl_fsrv_start(&afl->cmplog_fsrv, afl->argv, &afl->stop_soon,
afl->afl_env.afl_debug_child);
- } else {
-
- afl->cmplog_fsrv.map_size = new_map_size;
-
}
OKF("Cmplog forkserver successfully started");
}
+ if (afl->debug) {
+ printf("NORMAL %u, CMPLOG %u\n", afl->fsrv.map_size, afl->cmplog_fsrv.map_size);
+ fprintf(stderr, "NORMAL %u, CMPLOG %u\n", afl->fsrv.map_size, afl->cmplog_fsrv.map_size);
+ }
+
load_auto(afl);
if (extras_dir_cnt) {
diff --git a/src/afl-showmap.c b/src/afl-showmap.c
index 29b8456f..e98b9183 100644
--- a/src/afl-showmap.c
+++ b/src/afl-showmap.c
@@ -598,38 +598,7 @@ static void set_up_environment(afl_forkserver_t *fsrv) {
if (fsrv->qemu_mode) {
- u8 *qemu_preload = getenv("QEMU_SET_ENV");
- u8 *afl_preload = getenv("AFL_PRELOAD");
- u8 *buf;
-
- s32 i, afl_preload_size = strlen(afl_preload);
- for (i = 0; i < afl_preload_size; ++i) {
-
- if (afl_preload[i] == ',') {
-
- PFATAL(
- "Comma (',') is not allowed in AFL_PRELOAD when -Q is "
- "specified!");
-
- }
-
- }
-
- if (qemu_preload) {
-
- buf = alloc_printf("%s,LD_PRELOAD=%s,DYLD_INSERT_LIBRARIES=%s",
- qemu_preload, afl_preload, afl_preload);
-
- } else {
-
- buf = alloc_printf("LD_PRELOAD=%s,DYLD_INSERT_LIBRARIES=%s",
- afl_preload, afl_preload);
-
- }
-
- setenv("QEMU_SET_ENV", buf, 1);
-
- ck_free(buf);
+ /* afl-qemu-trace takes care of converting AFL_PRELOAD. */
} else {
@@ -945,31 +914,6 @@ int main(int argc, char **argv_orig, char **envp) {
if (optind == argc || !out_file) { usage(argv[0]); }
- if (fsrv->qemu_mode && getenv("AFL_USE_QASAN")) {
-
- u8 *preload = getenv("AFL_PRELOAD");
- u8 *libqasan = get_libqasan_path(argv_orig[0]);
-
- if (!preload) {
-
- setenv("AFL_PRELOAD", libqasan, 0);
-
- } else {
-
- u8 *result = ck_alloc(strlen(libqasan) + strlen(preload) + 2);
- strcpy(result, libqasan);
- strcat(result, " ");
- strcat(result, preload);
-
- setenv("AFL_PRELOAD", result, 1);
- ck_free(result);
-
- }
-
- ck_free(libqasan);
-
- }
-
if (in_dir) {
if (!out_file && !collect_coverage)
diff --git a/src/afl-tmin.c b/src/afl-tmin.c
index 6d04c652..7ef8b9bf 100644
--- a/src/afl-tmin.c
+++ b/src/afl-tmin.c
@@ -753,38 +753,7 @@ static void set_up_environment(afl_forkserver_t *fsrv) {
if (fsrv->qemu_mode) {
- u8 *qemu_preload = getenv("QEMU_SET_ENV");
- u8 *afl_preload = getenv("AFL_PRELOAD");
- u8 *buf;
-
- s32 i, afl_preload_size = strlen(afl_preload);
- for (i = 0; i < afl_preload_size; ++i) {
-
- if (afl_preload[i] == ',') {
-
- PFATAL(
- "Comma (',') is not allowed in AFL_PRELOAD when -Q is "
- "specified!");
-
- }
-
- }
-
- if (qemu_preload) {
-
- buf = alloc_printf("%s,LD_PRELOAD=%s,DYLD_INSERT_LIBRARIES=%s",
- qemu_preload, afl_preload, afl_preload);
-
- } else {
-
- buf = alloc_printf("LD_PRELOAD=%s,DYLD_INSERT_LIBRARIES=%s",
- afl_preload, afl_preload);
-
- }
-
- setenv("QEMU_SET_ENV", buf, 1);
-
- ck_free(buf);
+ /* afl-qemu-trace takes care of converting AFL_PRELOAD. */
} else {
@@ -1079,31 +1048,6 @@ int main(int argc, char **argv_orig, char **envp) {
check_environment_vars(envp);
setenv("AFL_NO_AUTODICT", "1", 1);
- if (fsrv->qemu_mode && getenv("AFL_USE_QASAN")) {
-
- u8 *preload = getenv("AFL_PRELOAD");
- u8 *libqasan = get_libqasan_path(argv_orig[0]);
-
- if (!preload) {
-
- setenv("AFL_PRELOAD", libqasan, 0);
-
- } else {
-
- u8 *result = ck_alloc(strlen(libqasan) + strlen(preload) + 2);
- strcpy(result, libqasan);
- strcat(result, " ");
- strcat(result, preload);
-
- setenv("AFL_PRELOAD", result, 1);
- ck_free(result);
-
- }
-
- ck_free(libqasan);
-
- }
-
/* initialize cmplog_mode */
shm.cmplog_mode = 0;