From 2cf19246e34676de887885380248fb07c5499ab1 Mon Sep 17 00:00:00 2001 From: Thomas HUET Date: Sat, 29 Jul 2017 16:26:05 +0200 Subject: [PATCH] 2.45b --- afl-fuzz.c | 6 ++--- afl-gcc.c | 2 ++ afl-showmap.c | 2 +- config.h | 2 +- docs/ChangeLog | 11 ++++++++ docs/README | 2 +- libtokencap/README.tokencap | 3 ++- libtokencap/libtokencap.so.c | 51 ++++++++++++++++++++++++++++++++++++ 8 files changed, 72 insertions(+), 7 deletions(-) diff --git a/afl-fuzz.c b/afl-fuzz.c index 562fd509..c7c00cd6 100644 --- a/afl-fuzz.c +++ b/afl-fuzz.c @@ -3310,10 +3310,10 @@ static u32 find_start_position(void) { i = read(fd, tmp, sizeof(tmp) - 1); (void)i; /* Ignore errors */ close(fd); - off = strstr(tmp, "cur_path : "); + off = strstr(tmp, "cur_path : "); if (!off) return 0; - ret = atoi(off + 17); + ret = atoi(off + 20); if (ret >= queued_paths) ret = 0; return ret; @@ -3401,7 +3401,7 @@ static void write_stats_file(double bitmap_cvg, double stability, double eps) { "paths_found : %u\n" "paths_imported : %u\n" "max_depth : %u\n" - "cur_path : %u\n" + "cur_path : %u\n" /* Must match find_start_position() */ "pending_favs : %u\n" "pending_total : %u\n" "variable_paths : %u\n" diff --git a/afl-gcc.c b/afl-gcc.c index fa3dec1a..a2b23240 100644 --- a/afl-gcc.c +++ b/afl-gcc.c @@ -287,6 +287,8 @@ static void edit_params(u32 argc, char** argv) { cc_params[cc_par_cnt++] = "-fno-builtin-strcasecmp"; cc_params[cc_par_cnt++] = "-fno-builtin-strncasecmp"; cc_params[cc_par_cnt++] = "-fno-builtin-memcmp"; + cc_params[cc_par_cnt++] = "-fno-builtin-strstr"; + cc_params[cc_par_cnt++] = "-fno-builtin-strcasestr"; } diff --git a/afl-showmap.c b/afl-showmap.c index 789082ff..46cbba5e 100644 --- a/afl-showmap.c +++ b/afl-showmap.c @@ -286,7 +286,7 @@ static void run_target(char** argv) { } - if (keep_cores) r.rlim_max = r.rlim_cur = 0; + if (!keep_cores) r.rlim_max = r.rlim_cur = 0; else r.rlim_max = r.rlim_cur = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &r); /* Ignore errors */ diff --git a/config.h b/config.h index 319fd162..d00f6211 100644 --- a/config.h +++ b/config.h @@ -21,7 +21,7 @@ /* Version string: */ -#define VERSION "2.44b" +#define VERSION "2.45b" /****************************************************** * * diff --git a/docs/ChangeLog b/docs/ChangeLog index 17f7d74e..fd76f59f 100644 --- a/docs/ChangeLog +++ b/docs/ChangeLog @@ -16,6 +16,17 @@ Not sure if you should upgrade? The lowest currently recommended version is 2.41b. If you're stuck on an earlier release, it's strongly advisable to get on with the times. +-------------- +Version 2.45b: +-------------- + + - Added strstr, strcasestr support to libtokencap. Contributed by + Daniel Hodson. + + - Fixed a resumption offset glitch spotted by Jakub Wilk. + + - There are definitely no bugs in afl-showmap -c now. + -------------- Version 2.44b: -------------- diff --git a/docs/README b/docs/README index 83781a6b..ac49599d 100644 --- a/docs/README +++ b/docs/README @@ -482,7 +482,7 @@ bug reports, or patches from: Joshua J. Drake Toby Hutton Rene Freingruber Sergey Davidoff Sami Liedes Craig Young - Andrzej Jackowski + Andrzej Jackowski Daniel Hodson Thank you! diff --git a/libtokencap/README.tokencap b/libtokencap/README.tokencap index 82d80c95..650739f2 100644 --- a/libtokencap/README.tokencap +++ b/libtokencap/README.tokencap @@ -32,7 +32,8 @@ part without mucking with CFLAGS in Makefiles, you can set AFL_NO_BUILTIN=1 when using afl-gcc. This setting specifically adds the following flags: -fno-builtin-strcmp -fno-builtin-strncmp -fno-builtin-strcasecmp - -fno-builtin-strcasencmp -fno-builtin-memcmp + -fno-builtin-strcasencmp -fno-builtin-memcmp -fno-builtin-strstr + -fno-builtin-strcasestr The next step is simply loading this library via LD_PRELOAD. The optimal usage pattern is to allow afl-fuzz to fuzz normally for a while and build up a corpus, diff --git a/libtokencap/libtokencap.so.c b/libtokencap/libtokencap.so.c index 696c913d..41997f04 100644 --- a/libtokencap/libtokencap.so.c +++ b/libtokencap/libtokencap.so.c @@ -241,6 +241,57 @@ int memcmp(const void* mem1, const void* mem2, size_t len) { } +#undef strstr + +const char* strstr(const char* haystack, const char* needle) { + + if (__tokencap_is_ro(haystack)) + __tokencap_dump(haystack, strlen(haystack), 1); + + if (__tokencap_is_ro(needle)) + __tokencap_dump(needle, strlen(needle), 1); + + do { + const char* n = needle; + const char* h = haystack; + + while(*n && *h && *n == *h) n++, h++; + + if(!*n) return haystack; + + } while (*(haystack++)); + + return 0; + +} + + +#undef strcasestr + +const char* strcasestr(const char* haystack, const char* needle) { + + if (__tokencap_is_ro(haystack)) + __tokencap_dump(haystack, strlen(haystack), 1); + + if (__tokencap_is_ro(needle)) + __tokencap_dump(needle, strlen(needle), 1); + + do { + + const char* n = needle; + const char* h = haystack; + + while(*n && *h && tolower(*n) == tolower(*h)) n++, h++; + + if(!*n) return haystack; + + } while(*(haystack++)); + + return 0; + +} + + /* Init code to open the output file (or default to stderr). */ __attribute__((constructor)) void __tokencap_init(void) {