diff options
author | hexcoder <hexcoder-@users.noreply.github.com> | 2019-10-28 16:16:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-28 16:16:54 +0100 |
commit | f9bf0bd90ed51d3d4e177e737598ece1e9c29773 (patch) | |
tree | f1ef6b8c3f2ea10ad57f11991914df45ada25753 | |
parent | 0df37d0fa1452f7a9c06474a26da71d3442ae319 (diff) | |
parent | 942f8d0ec9bed45c9038112aef7cd9b8a05f6f30 (diff) | |
download | afl++-f9bf0bd90ed51d3d4e177e737598ece1e9c29773.tar.gz |
Merge pull request #90 from devnexen/libtokencap_netbsd_fix
Fix proposal for libtokencap
-rw-r--r-- | libtokencap/Makefile | 3 | ||||
-rw-r--r-- | libtokencap/libtokencap.so.c | 18 |
2 files changed, 16 insertions, 5 deletions
diff --git a/libtokencap/Makefile b/libtokencap/Makefile index 441412c7..df2426ed 100644 --- a/libtokencap/Makefile +++ b/libtokencap/Makefile @@ -33,6 +33,9 @@ endif ifeq "$(shell uname)" "OpenBSD" TARGETS = libtokencap.so endif +ifeq "$(shell uname)" "NetBSD" + TARGETS = libtokencap.so +endif all: $(TARGETS) libtokencap.so: libtokencap.so.c ../config.h diff --git a/libtokencap/libtokencap.so.c b/libtokencap/libtokencap.so.c index 7ed231fe..e1977127 100644 --- a/libtokencap/libtokencap.so.c +++ b/libtokencap/libtokencap.so.c @@ -23,6 +23,7 @@ #include <string.h> #include <ctype.h> #include <unistd.h> +#include <fcntl.h> #include "../types.h" #include "../config.h" @@ -49,7 +50,7 @@ static struct mapping { void *st, *en; } __tokencap_ro[MAX_MAPPINGS]; static u32 __tokencap_ro_cnt; static u8 __tokencap_ro_loaded; -static FILE* __tokencap_out_file; +static int __tokencap_out_file = -1; /* Identify read-only regions in memory. Only parameters that fall into these ranges are worth dumping when passed to strcmp() and so on. Read-write @@ -211,7 +212,7 @@ static void __tokencap_dump(const u8* ptr, size_t len, u8 is_text) { u32 i; u32 pos = 0; - if (len < MIN_AUTO_EXTRA || len > MAX_AUTO_EXTRA || !__tokencap_out_file) + if (len < MIN_AUTO_EXTRA || len > MAX_AUTO_EXTRA || __tokencap_out_file == -1) return; for (i = 0; i < len; i++) { @@ -237,7 +238,9 @@ static void __tokencap_dump(const u8* ptr, size_t len, u8 is_text) { buf[pos] = 0; - fprintf(__tokencap_out_file, "\"%s\"\n", buf); + write(__tokencap_out_file, "\"", 1); + write(__tokencap_out_file, buf, pos); + write(__tokencap_out_file, "\"\n", 2); } @@ -403,8 +406,13 @@ char* strcasestr(const char* haystack, const char* needle) { __attribute__((constructor)) void __tokencap_init(void) { u8* fn = getenv("AFL_TOKEN_FILE"); - if (fn) __tokencap_out_file = fopen(fn, "a"); - if (!__tokencap_out_file) __tokencap_out_file = stderr; + if (fn) __tokencap_out_file = open(fn, O_RDWR | O_CREAT | O_APPEND, 0655); + if (__tokencap_out_file == -1) __tokencap_out_file = STDERR_FILENO; } +/* closing as best as we can the tokens file */ +__attribute__((destructor)) void __tokencap_shutdown(void) { + if (__tokencap_out_file != STDERR_FILENO) close(__tokencap_out_file); +} + |