fix for afl-showmap with -Q
MODIFY
GNUmakefile
GNUmakefile
@@ -341,7 +341,7 @@ src/third_party/libradamsa/libradamsa.so: src/third_party/libradamsa/libradamsa.
afl-fuzz: $(COMM_HDR) include/afl-fuzz.h $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o | test_x86
$(CC) $(CFLAGS) $(CFLAGS_FLTO) $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o -o $@ $(PYFLAGS) $(LDFLAGS)
-afl-showmap: src/afl-showmap.c src/afl-common.o src/afl-sharedmem.o $(COMM_HDR) | test_x86
+afl-showmap: src/afl-showmap.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o $(COMM_HDR) | test_x86
$(CC) $(CFLAGS) $(CFLAGS_FLTO) src/$@.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o -o $@ $(LDFLAGS)
afl-tmin: src/afl-tmin.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o $(COMM_HDR) | test_x86

MODIFY
docs/Changelog.md
docs/Changelog.md
@@ -27,6 +27,7 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
- better dependency checks
- unicorn_mode:
- better submodule handling
+ - afl-showmap: fix for -Q mode
- all:
- forkserver communication now also used for error reporting
- fix 32 bit build options

MODIFY
src/afl-showmap.c
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);
}

fix for afl-showmap with -Q