From a56354a893fa5aa330773fbd0c28c5561ad1ea51 Mon Sep 17 00:00:00 2001 From: van Hauser Date: Mon, 27 Apr 2020 19:30:32 +0200 Subject: fix for afl-showmap with -Q --- src/afl-showmap.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/afl-showmap.c b/src/afl-showmap.c index af6c2b1a..98280203 100644 --- a/src/afl-showmap.c +++ b/src/afl-showmap.c @@ -714,7 +714,6 @@ int main(int argc, char **argv_orig, char **envp) { case 'Q': if (fsrv->qemu_mode) { FATAL("Multiple -Q options not supported"); } - if (!mem_limit_given) { fsrv->mem_limit = MEM_LIMIT_QEMU; } fsrv->qemu_mode = 1; break; @@ -722,7 +721,6 @@ int main(int argc, char **argv_orig, char **envp) { case 'U': if (unicorn_mode) { FATAL("Multiple -U options not supported"); } - if (!mem_limit_given) { fsrv->mem_limit = MEM_LIMIT_UNICORN; } unicorn_mode = 1; break; @@ -733,8 +731,6 @@ int main(int argc, char **argv_orig, char **envp) { fsrv->qemu_mode = 1; use_wine = 1; - if (!mem_limit_given) { fsrv->mem_limit = 0; } - break; case 'b': @@ -772,6 +768,9 @@ int main(int argc, char **argv_orig, char **envp) { if (optind == argc || !out_file) { usage(argv[0]); } + if (fsrv->qemu_mode && !mem_limit_given) { fsrv->mem_limit = MEM_LIMIT_QEMU; } + if (unicorn_mode && !mem_limit_given) { fsrv->mem_limit = MEM_LIMIT_UNICORN; } + check_environment_vars(envp); sharedmem_t shm = {0}; @@ -780,6 +779,14 @@ int main(int argc, char **argv_orig, char **envp) { set_up_environment(fsrv); + i = 0; + while (argv[i] != NULL && !arg_offset) { + + if (strcmp(argv[i], "@@") == 0) arg_offset = i; + i++; + + } + fsrv->target_path = find_binary(argv[optind]); if (!quiet_mode) { @@ -800,12 +807,6 @@ int main(int argc, char **argv_orig, char **envp) { } - for (i = optind; i < argc; i++) { - - if (strcmp(argv[i], "@@") == 0) { arg_offset = i; } - - } - if (fsrv->qemu_mode) { if (use_wine) { @@ -826,6 +827,15 @@ int main(int argc, char **argv_orig, char **envp) { } + int arg_offset2 = 0; + i = 0; + while (use_argv[i] != NULL && !arg_offset2) { + + if (strcmp(use_argv[i], "@@") == 0) { arg_offset2 = i; } + i++; + + } + if (in_dir) { DIR * dir_in, *dir_out; @@ -870,10 +880,11 @@ int main(int argc, char **argv_orig, char **envp) { fsrv->out_fd = open(stdin_file, O_RDWR | O_CREAT | O_EXCL, 0600); if (fsrv->out_fd < 0) { PFATAL("Unable to create '%s'", out_file); } - if (arg_offset && argv[arg_offset] != stdin_file) { + if (arg_offset && use_argv[arg_offset] != stdin_file) { ck_free(argv[arg_offset]); argv[arg_offset] = strdup(stdin_file); + use_argv[arg_offset2] = argv[arg_offset]; } @@ -888,8 +899,6 @@ int main(int argc, char **argv_orig, char **envp) { } SAYF("\n"); - SAYF(cMGN "[D]" cRST " %d - %d = %d, %s\n", arg_offset, optind, - arg_offset - optind, infile); } -- cgit 1.4.1 From 087c368242f7db2da2564617acf6dd63bf8b671c Mon Sep 17 00:00:00 2001 From: van Hauser Date: Mon, 27 Apr 2020 22:10:08 +0200 Subject: better fix for showmap --- src/afl-showmap.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/afl-showmap.c b/src/afl-showmap.c index 98280203..3b3bdefe 100644 --- a/src/afl-showmap.c +++ b/src/afl-showmap.c @@ -779,14 +779,6 @@ int main(int argc, char **argv_orig, char **envp) { set_up_environment(fsrv); - i = 0; - while (argv[i] != NULL && !arg_offset) { - - if (strcmp(argv[i], "@@") == 0) arg_offset = i; - i++; - - } - fsrv->target_path = find_binary(argv[optind]); if (!quiet_mode) { @@ -827,11 +819,10 @@ int main(int argc, char **argv_orig, char **envp) { } - int arg_offset2 = 0; i = 0; - while (use_argv[i] != NULL && !arg_offset2) { + while (use_argv[i] != NULL && !arg_offset) { - if (strcmp(use_argv[i], "@@") == 0) { arg_offset2 = i; } + if (strcmp(use_argv[i], "@@") == 0) { arg_offset = i; } i++; } @@ -880,11 +871,9 @@ int main(int argc, char **argv_orig, char **envp) { fsrv->out_fd = open(stdin_file, O_RDWR | O_CREAT | O_EXCL, 0600); if (fsrv->out_fd < 0) { PFATAL("Unable to create '%s'", out_file); } - if (arg_offset && use_argv[arg_offset] != stdin_file) { + if (use_argv[arg_offset] != stdin_file) { - ck_free(argv[arg_offset]); - argv[arg_offset] = strdup(stdin_file); - use_argv[arg_offset2] = argv[arg_offset]; + use_argv[arg_offset] = strdup(stdin_file); } -- cgit 1.4.1 From fbd9994f6f959def9c228b81711706bbc5be8cde Mon Sep 17 00:00:00 2001 From: van Hauser Date: Mon, 27 Apr 2020 22:11:58 +0200 Subject: better fix for showmap --- src/afl-showmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/afl-showmap.c b/src/afl-showmap.c index 3b3bdefe..a51d520d 100644 --- a/src/afl-showmap.c +++ b/src/afl-showmap.c @@ -871,7 +871,7 @@ int main(int argc, char **argv_orig, char **envp) { fsrv->out_fd = open(stdin_file, O_RDWR | O_CREAT | O_EXCL, 0600); if (fsrv->out_fd < 0) { PFATAL("Unable to create '%s'", out_file); } - if (use_argv[arg_offset] != stdin_file) { + if (arg_offset && use_argv[arg_offset] != stdin_file) { use_argv[arg_offset] = strdup(stdin_file); -- cgit 1.4.1