diff options
author | Robert Swiecki <robert@swiecki.net> | 2017-12-18 03:44:33 +0100 |
---|---|---|
committer | Robert Swiecki <robert@swiecki.net> | 2017-12-18 03:44:33 +0100 |
commit | b0cb93b9f70cc347ac3514ea56ad841e690adf3c (patch) | |
tree | b58314ebb4b9891ce8e8fe757cf1e75f318bcea2 | |
parent | eba27171213942cb463e68f04ad2f2b70012d106 (diff) | |
download | honggfuzz-b0cb93b9f70cc347ac3514ea56ad841e690adf3c.tar.gz |
libhfuzz: use uintptr_t instead of void* for address passing
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | libhfuzz/instrument.c | 6 | ||||
-rw-r--r-- | libhfuzz/instrument.h | 4 | ||||
-rw-r--r-- | libhfuzz/libhfuzz.h | 2 | ||||
-rw-r--r-- | libhfuzz/memorycmp.c | 77 |
5 files changed, 50 insertions, 41 deletions
@@ -26,7 +26,7 @@ LD = $(CC) BIN := honggfuzz HFUZZ_CC_BINS := hfuzz_cc/hfuzz-clang hfuzz_cc/hfuzz-clang++ hfuzz_cc/hfuzz-gcc hfuzz_cc/hfuzz-g++ HFUZZ_CC_SRCS := hfuzz_cc/hfuzz-cc.c -COMMON_CFLAGS := -D_GNU_SOURCE -Wall -Werror -Wframe-larger-than=131072 -Wno-format-truncation -Wno-unknown-warning -I. +COMMON_CFLAGS := -D_GNU_SOURCE -Wall -Werror -Wframe-larger-than=131072 -Wno-format-truncation -I. COMMON_LDFLAGS := -lm libcommon/libcommon.a COMMON_SRCS := $(sort $(wildcard *.c)) CFLAGS ?= -O3 diff --git a/libhfuzz/instrument.c b/libhfuzz/instrument.c index e3184834..77a7a640 100644 --- a/libhfuzz/instrument.c +++ b/libhfuzz/instrument.c @@ -269,10 +269,8 @@ ATTRIBUTE_X86_REQUIRE_SSE42 void __sanitizer_cov_trace_pc_guard(uint32_t* guard) *guard = 0U; } -void instrumentCmpMap(void* addr, unsigned int n) { instrumentUpdateCmpMap(addr, n); } - -void instrumentUpdateCmpMap(void* addr, unsigned int n) { - uintptr_t pos = (uintptr_t)addr % _HF_PERF_BITMAP_SIZE_16M; +void instrumentUpdateCmpMap(uintptr_t addr, unsigned int n) { + uintptr_t pos = addr % _HF_PERF_BITMAP_SIZE_16M; uint8_t v = n > 254 ? 254 : n; uint8_t prev = ATOMIC_GET(feedback->bbMapCmp[pos]); if (prev < v) { diff --git a/libhfuzz/instrument.h b/libhfuzz/instrument.h index 72bafb02..5471cc1b 100644 --- a/libhfuzz/instrument.h +++ b/libhfuzz/instrument.h @@ -24,6 +24,8 @@ #ifndef _HF_LIBHFUZZ_INSTRUMENT_H_ #define _HF_LIBHFUZZ_INSTRUMENT_H_ -void instrumentUpdateCmpMap(void* addr, unsigned int n); +#include <inttypes.h> + +void instrumentUpdateCmpMap(uintptr_t addr, unsigned int n); #endif diff --git a/libhfuzz/libhfuzz.h b/libhfuzz/libhfuzz.h index 9f0c1d88..a5f19561 100644 --- a/libhfuzz/libhfuzz.h +++ b/libhfuzz/libhfuzz.h @@ -46,7 +46,7 @@ void HF_ITER(const uint8_t** buf_ptr, size_t* len_ptr); * addr: address of original comparison * n: new value (only if better than the old/current value) */ -void instrumentCmpMap(void* addr, unsigned int n); +void instrumentUpdateCmpMap(void* addr, unsigned int n); /* * Instrumented comparison functions diff --git a/libhfuzz/memorycmp.c b/libhfuzz/memorycmp.c index 7b80932d..e3c8c58b 100644 --- a/libhfuzz/memorycmp.c +++ b/libhfuzz/memorycmp.c @@ -1,11 +1,20 @@ #include <ctype.h> +#include <inttypes.h> #include <string.h> #include "libhfuzz/instrument.h" int hfuzz_module_memorycmp = 0; -static inline int _strcmp(const char* s1, const char* s2, void* addr) { +#if 0 /* Might be useful with defined(__x86_64__) */ +#define RET_CALL_CHAIN \ + ((uintptr_t)__builtin_return_address(0) & 0xFFF) | \ + ((uintptr_t)__builtin_return_address(1) << 12) +#else +#define RET_CALL_CHAIN (uintptr_t) __builtin_return_address(0) +#endif /* defined(x86_64) */ + +static inline int _strcmp(const char* s1, const char* s2, uintptr_t addr) { unsigned int v = 0; size_t i; @@ -19,7 +28,7 @@ static inline int _strcmp(const char* s1, const char* s2, void* addr) { return (s1[i] - s2[i]); } -static inline int _strcasecmp(const char* s1, const char* s2, void* addr) { +static inline int _strcasecmp(const char* s1, const char* s2, uintptr_t addr) { unsigned int v = 0; size_t i; @@ -33,7 +42,7 @@ static inline int _strcasecmp(const char* s1, const char* s2, void* addr) { return (tolower(s1[i]) - tolower(s2[i])); } -static inline int _strncmp(const char* s1, const char* s2, size_t n, void* addr) { +static inline int _strncmp(const char* s1, const char* s2, size_t n, uintptr_t addr) { if (n == 0) { return 0; } @@ -56,7 +65,7 @@ static inline int _strncmp(const char* s1, const char* s2, size_t n, void* addr) return ret; } -static inline int _strncasecmp(const char* s1, const char* s2, size_t n, void* addr) { +static inline int _strncasecmp(const char* s1, const char* s2, size_t n, uintptr_t addr) { if (n == 0) { return 0; } @@ -79,7 +88,7 @@ static inline int _strncasecmp(const char* s1, const char* s2, size_t n, void* a return ret; } -static inline char* _strstr(const char* haystack, const char* needle, void* addr) { +static inline char* _strstr(const char* haystack, const char* needle, uintptr_t addr) { size_t needle_len = strlen(needle); for (size_t i = 0; haystack[i]; i++) { if (_strncmp(&haystack[i], needle, needle_len, addr) == 0) { @@ -89,7 +98,7 @@ static inline char* _strstr(const char* haystack, const char* needle, void* addr return NULL; } -static inline char* _strcasestr(const char* haystack, const char* needle, void* addr) { +static inline char* _strcasestr(const char* haystack, const char* needle, uintptr_t addr) { size_t needle_len = strlen(needle); for (size_t i = 0; haystack[i]; i++) { if (_strncasecmp(&haystack[i], needle, needle_len, addr) == 0) { @@ -99,7 +108,7 @@ static inline char* _strcasestr(const char* haystack, const char* needle, void* return NULL; } -static inline int _memcmp(const void* m1, const void* m2, size_t n, void* addr) { +static inline int _memcmp(const void* m1, const void* m2, size_t n, uintptr_t addr) { if (n == 0) { return 0; } @@ -122,8 +131,8 @@ static inline int _memcmp(const void* m1, const void* m2, size_t n, void* addr) return ret; } -static inline void* _memmem( - const void* haystack, size_t haystacklen, const void* needle, size_t needlelen, void* addr) { +static inline void* _memmem(const void* haystack, size_t haystacklen, const void* needle, + size_t needlelen, uintptr_t addr) { if (needlelen > haystacklen) { return NULL; } @@ -148,74 +157,74 @@ static inline void* _memmem( /* Typical libc wrappers */ HF_WEAK_WRAP(int, strcmp, const char* s1, const char* s2) { - return _strcmp(s1, s2, __builtin_return_address(0)); + return _strcmp(s1, s2, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, strcasecmp, const char* s1, const char* s2) { - return _strcasecmp(s1, s2, __builtin_return_address(0)); + return _strcasecmp(s1, s2, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, strncmp, const char* s1, const char* s2, size_t n) { - return _strncmp(s1, s2, n, __builtin_return_address(0)); + return _strncmp(s1, s2, n, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, strncasecmp, const char* s1, const char* s2, size_t n) { - return _strncasecmp(s1, s2, n, __builtin_return_address(0)); + return _strncasecmp(s1, s2, n, RET_CALL_CHAIN); } HF_WEAK_WRAP(char*, strstr, const char* haystack, const char* needle) { - return _strstr(haystack, needle, __builtin_return_address(0)); + return _strstr(haystack, needle, RET_CALL_CHAIN); } HF_WEAK_WRAP(char*, strcasestr, const char* haystack, const char* needle) { - return _strcasestr(haystack, needle, __builtin_return_address(0)); + return _strcasestr(haystack, needle, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, memcmp, const void* m1, const void* m2, size_t n) { - return _memcmp(m1, m2, n, __builtin_return_address(0)); + return _memcmp(m1, m2, n, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, bcmp, const void* m1, const void* m2, size_t n) { - return _memcmp(m1, m2, n, __builtin_return_address(0)); + return _memcmp(m1, m2, n, RET_CALL_CHAIN); } HF_WEAK_WRAP( void*, memmem, const void* haystack, size_t haystacklen, const void* needle, size_t needlelen) { - return _memmem(haystack, haystacklen, needle, needlelen, __builtin_return_address(0)); + return _memmem(haystack, haystacklen, needle, needlelen, RET_CALL_CHAIN); } /* * Apache's httpd wrappers */ HF_WEAK_WRAP(int, ap_cstr_casecmp, const char* s1, const char* s2) { - return _strcasecmp(s1, s2, __builtin_return_address(0)); + return _strcasecmp(s1, s2, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, ap_cstr_casecmpn, const char* s1, const char* s2, size_t n) { - return _strncasecmp(s1, s2, n, __builtin_return_address(0)); + return _strncasecmp(s1, s2, n, RET_CALL_CHAIN); } HF_WEAK_WRAP(const char*, ap_strcasestr, const char* s1, const char* s2) { - return _strcasestr(s1, s2, __builtin_return_address(0)); + return _strcasestr(s1, s2, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, apr_cstr_casecmp, const char* s1, const char* s2) { - return _strcasecmp(s1, s2, __builtin_return_address(0)); + return _strcasecmp(s1, s2, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, apr_cstr_casecmpn, const char* s1, const char* s2, size_t n) { - return _strncasecmp(s1, s2, n, __builtin_return_address(0)); + return _strncasecmp(s1, s2, n, RET_CALL_CHAIN); } /* * *SSL wrappers */ HF_WEAK_WRAP(int, CRYPTO_memcmp, const void* m1, const void* m2, size_t len) { - return _memcmp(m1, m2, len, __builtin_return_address(0)); + return _memcmp(m1, m2, len, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, OPENSSL_memcmp, const void* m1, const void* m2, size_t len) { - return _memcmp(m1, m2, len, __builtin_return_address(0)); + return _memcmp(m1, m2, len, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, OPENSSL_strcasecmp, const char* s1, const char* s2) { - return _strcasecmp(s1, s2, __builtin_return_address(0)); + return _strcasecmp(s1, s2, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, OPENSSL_strncasecmp, const char* s1, const char* s2, size_t len) { - return _strncasecmp(s1, s2, len, __builtin_return_address(0)); + return _strncasecmp(s1, s2, len, RET_CALL_CHAIN); } /* @@ -234,7 +243,7 @@ HF_WEAK_WRAP(int, xmlStrncmp, const char* s1, const char* s2, int len) { if (s2 == NULL) { return 1; } - return _strncmp(s1, s2, (size_t)len, __builtin_return_address(0)); + return _strncmp(s1, s2, (size_t)len, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, xmlStrcmp, const char* s1, const char* s2) { @@ -247,7 +256,7 @@ HF_WEAK_WRAP(int, xmlStrcmp, const char* s1, const char* s2) { if (s2 == NULL) { return 1; } - return _strcmp(s1, s2, __builtin_return_address(0)); + return _strcmp(s1, s2, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, xmlStrEqual, const char* s1, const char* s2) { @@ -260,7 +269,7 @@ HF_WEAK_WRAP(int, xmlStrEqual, const char* s1, const char* s2) { if (s2 == NULL) { return 0; } - if (_strcmp(s1, s2, __builtin_return_address(0)) == 0) { + if (_strcmp(s1, s2, RET_CALL_CHAIN) == 0) { return 1; } return 0; @@ -276,7 +285,7 @@ HF_WEAK_WRAP(int, xmlStrcasecmp, const char* s1, const char* s2) { if (s2 == NULL) { return 1; } - return _strcasecmp(s1, s2, __builtin_return_address(0)); + return _strcasecmp(s1, s2, RET_CALL_CHAIN); } HF_WEAK_WRAP(int, xmlStrncasecmp, const char* s1, const char* s2, int len) { @@ -292,7 +301,7 @@ HF_WEAK_WRAP(int, xmlStrncasecmp, const char* s1, const char* s2, int len) { if (s2 == NULL) { return 1; } - return _strncasecmp(s1, s2, (size_t)len, __builtin_return_address(0)); + return _strncasecmp(s1, s2, (size_t)len, RET_CALL_CHAIN); } HF_WEAK_WRAP(const char*, xmlStrstr, const char* haystack, const char* needle) { @@ -302,7 +311,7 @@ HF_WEAK_WRAP(const char*, xmlStrstr, const char* haystack, const char* needle) { if (needle == NULL) { return NULL; } - return _strstr(haystack, needle, __builtin_return_address(0)); + return _strstr(haystack, needle, RET_CALL_CHAIN); } HF_WEAK_WRAP(const char*, xmlStrcasestr, const char* haystack, const char* needle) { @@ -312,5 +321,5 @@ HF_WEAK_WRAP(const char*, xmlStrcasestr, const char* haystack, const char* needl if (needle == NULL) { return NULL; } - return _strcasestr(haystack, needle, __builtin_return_address(0)); + return _strcasestr(haystack, needle, RET_CALL_CHAIN); } |