afl-showmap fix
MODIFY
afl-cmin
afl-cmin
@@ -397,7 +397,7 @@ BEGIN {
system( "AFL_CMIN_ALLOW_ANY=1 \""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"/"fn"\" -Z "extra_par" -- \""target_bin"\" "prog_args_string" <\""in_dir"/"fn"\"")
}
} else {
- printf " Processing "in_count" files (forkserver mode)..."
+ printf " Processing "in_count" files (forkserver mode)...\n"
system( "AFL_CMIN_ALLOW_ANY=1 \""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -i \""in_dir"\" -- \""target_bin"\" "prog_args_string" </dev/null")
}

MODIFY
libdislocator/libdislocator.so.c
libdislocator/libdislocator.so.c
#if __STDC_VERSION__ < 201112L
// use this hack if not C11
-typedef struct { long long __ll; long double __ld; } max_align_t;
+typedef struct {
+
+ long long __ll;
+ long double __ld;
+
+} max_align_t;
+
#endif
#define ALLOC_ALIGN_SIZE (_Alignof(max_align_t))

MODIFY
src/afl-common.c
src/afl-common.c
@@ -72,6 +72,10 @@ void detect_file_args(char** argv, u8* prog_in) {
if (!prog_in) FATAL("@@ syntax is not supported by this tool.");
+ use_stdin = 0;
+
+ if (prog_in[0] != 0) { // not afl-showmap special case
+
/* Be sure that we're always using fully-qualified paths. */
if (prog_in[0] == '/')
@@ -79,8 +83,6 @@ void detect_file_args(char** argv, u8* prog_in) {
else
aa_subst = alloc_printf("%s/%s", cwd, prog_in);
- use_stdin = 0;
-
/* Construct a replacement argv value. */
*aa_loc = 0;
@@ -92,6 +94,8 @@ void detect_file_args(char** argv, u8* prog_in) {
}
+ }
+
i++;
}

MODIFY
src/afl-fuzz-stats.c
src/afl-fuzz-stats.c
@@ -765,8 +765,8 @@ void show_init_stats(void) {
WARNF(cLRD "Some test cases are huge (%s) - see %s/perf_tips.md!",
DMS(max_len), doc_path);
else if (max_len > 10 * 1024)
- WARNF("Some test cases are big (%s) - see %s/perf_tips.md.",
- DMS(max_len), doc_path);
+ WARNF("Some test cases are big (%s) - see %s/perf_tips.md.", DMS(max_len),
+ doc_path);
if (useless_at_start && !in_bitmap)
WARNF(cLRD "Some test cases look useless. Consider using a smaller set.");

MODIFY
src/afl-showmap.c
src/afl-showmap.c
@@ -89,8 +89,7 @@ u32 exec_tmout; /* Exec timeout (ms) */
static u32 total, highest; /* tuple content information */
static u32 in_len, /* Input data length */
- arg_offset,
- total_execs; /* Total number of execs */
+ arg_offset, total_execs; /* Total number of execs */
u64 mem_limit = MEM_LIMIT; /* Memory limit (MB) */
@@ -272,19 +271,13 @@ static s32 write_to_file(u8* path, u8* mem, u32 len) {
static void write_to_testcase(void* mem, u32 len) {
- if (use_stdin) {
-
lseek(out_fd, 0, SEEK_SET);
-
ck_write(out_fd, mem, len, out_file);
-
if (ftruncate(out_fd, len)) PFATAL("ftruncate() failed");
lseek(out_fd, 0, SEEK_SET);
}
-}
-
/* Execute target application. Returns 0 if the changes are a dud, or
1 if they should be kept. */
@@ -390,7 +383,8 @@ u32 read_file(u8 *in_file) {
if (fd < 0) WARNF("Unable to open '%s'", in_file);
- if (fstat(fd, &st) || !st.st_size) WARNF("Zero-sized input file '%s'.", in_file);
+ if (fstat(fd, &st) || !st.st_size)
+ WARNF("Zero-sized input file '%s'.", in_file);
in_len = st.st_size;
in_data = ck_alloc_nozero(in_len);
@@ -402,6 +396,7 @@ u32 read_file(u8 *in_file) {
// OKF("Read %u byte%s from '%s'.", in_len, in_len == 1 ? "" : "s", in_file);
return in_len;
+
}
/* Execute target application. */
@@ -643,7 +638,8 @@ static void usage(u8* argv0) {
"Other settings:\n\n"
- " -i dir - process all files in this directory, -o must be a directory\n"
+ " -i dir - process all files in this directory, -o must be a "
+ "directory\n"
" and each bitmap will be written there individually.\n"
" -q - sink program's output and don't show messages\n"
" -e - show edge coverage only, ignore hit counts\n"
@@ -907,11 +903,10 @@ int main(int argc, char** argv) {
}
- detect_file_args(argv + optind, at_file);
+ detect_file_args(argv + optind, "");
for (i = optind; i < argc; i++)
- if (strcmp(argv[i], "@@") == 0)
- arg_offset = i;
+ if (strcmp(argv[i], "@@") == 0) arg_offset = i;
if (qemu_mode) {
@@ -940,9 +935,6 @@ int main(int argc, char** argv) {
if (mkdir(out_file, 0700))
PFATAL("cannot create output directory %s", out_file);
- if (arg_offset) argv[arg_offset] = infile;
- else {
-
u8* use_dir = ".";
if (access(use_dir, R_OK | W_OK | X_OK)) {
@@ -958,22 +950,37 @@ int main(int argc, char** argv) {
out_fd = open(stdin_file, O_RDWR | O_CREAT | O_EXCL, 0600);
if (out_fd < 0) PFATAL("Unable to create '%s'", out_file);
+ if (arg_offset) argv[arg_offset] = stdin_file;
+
+ if (getenv("AFL_DEBUG")) {
+
+ int i = optind;
+ SAYF(cMGN "[D]" cRST " %s:", target_path);
+ while (argv[i] != NULL)
+ SAYF(" \"%s\"", argv[i++]);
+ SAYF("\n");
+ SAYF(cMGN "[D]" cRST " %d - %d = %d, %s\n", arg_offset, optind,
+ arg_offset - optind, infile);
+
}
init_forkserver(use_argv);
while (done == 0 && (dir_ent = readdir(dir_in))) {
- if (dir_ent->d_name[0] == '.') continue; // skip anything that starts with '.'
+ if (dir_ent->d_name[0] == '.')
+ continue; // skip anything that starts with '.'
if (dir_ent->d_type != DT_REG) continue; // only regular files
snprintf(infile, sizeof(infile), "%s/%s", in_dir, dir_ent->d_name);
snprintf(outfile, sizeof(outfile), "%s/%s", out_file, dir_ent->d_name);
if (read_file(infile)) {
+
run_target_forkserver(use_argv, in_data, in_len);
ck_free(in_data);
tcnt = write_results_to_file(outfile);
+
}
}
@@ -998,3 +1005,4 @@ int main(int argc, char** argv) {
exit(child_crashed * 2 + child_timed_out);
}
+

afl-showmap fix