From df02b9d41e6518b3f0a61c07849babe33ec89ba3 Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Wed, 21 Feb 2018 21:20:13 +0100 Subject: [PATCH] make hfuzz-cc workable under macos --- Makefile | 2 +- hfuzz_cc/hfuzz-cc.c | 5 +++++ honggfuzz.c | 2 +- libhfuzz/persistent.c | 22 ++++++++++++---------- mac/arch.c | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index c2b491261..ca3af4cbe 100644 --- a/Makefile +++ b/Makefile @@ -433,7 +433,7 @@ linux/trace.o: libhfcommon/log.h linux/bfd.h linux/unwind.h sancov.h linux/trace.o: sanitizers.h socketfuzzer.h subproc.h linux/unwind.o: linux/unwind.h honggfuzz.h libhfcommon/util.h linux/unwind.o: libhfcommon/common.h libhfcommon/log.h -mac/arch.o: arch.h honggfuzz.h libhfcommon/util.h libhfcommon/common.h +mac/arch.o: arch.h honggfuzz.h libhfcommon/util.h fuzz.h libhfcommon/common.h mac/arch.o: libhfcommon/files.h libhfcommon/common.h libhfcommon/log.h mac/arch.o: sancov.h subproc.h posix/arch.o: arch.h honggfuzz.h libhfcommon/util.h fuzz.h diff --git a/hfuzz_cc/hfuzz-cc.c b/hfuzz_cc/hfuzz-cc.c index 654e48459..0a121e6d9 100644 --- a/hfuzz_cc/hfuzz-cc.c +++ b/hfuzz_cc/hfuzz-cc.c @@ -376,9 +376,14 @@ static int ldMode(int argc, char** argv) { args[j++] = getLibHFNetDriverPath(); /* Pull modules defining the following symbols (if they exist) */ +#ifndef _HF_ARCH_DARWIN args[j++] = "-Wl,-u,LIBHFNETDRIVER_module_main", args[j++] = "-Wl,-u,LIBHFUZZ_module_instrument"; args[j++] = "-Wl,-u,LIBHFUZZ_module_memorycmp"; +#else /* _HF_ARCH_DARWIN */ + args[j++] = "-Wl,-u,_LIBHFUZZ_module_instrument"; + args[j++] = "-Wl,-u,_LIBHFUZZ_module_memorycmp"; +#endif /* _HF_ARCH_DARWIN */ /* Needed by the libhfcommon */ args[j++] = "-lpthread"; diff --git a/honggfuzz.c b/honggfuzz.c index 366723fd6..2a0c34955 100644 --- a/honggfuzz.c +++ b/honggfuzz.c @@ -90,7 +90,7 @@ static void setupRLimits(void) { LOG_E("RLIMIT_NOFILE max limit < 1024 (%u). Expect troubles!", (unsigned int)rlim.rlim_max); return; } - rlim.rlim_cur = MIN(1024, rlim.rlim_max); // we don't need more + rlim.rlim_cur = MIN(1024, rlim.rlim_max); // we don't need more if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) { PLOG_E("Couldn't setrlimit(RLIMIT_NOFILE, cur=max=%u)", (unsigned int)rlim.rlim_max); } diff --git a/libhfuzz/persistent.c b/libhfuzz/persistent.c index 861724e71..be3698cb2 100644 --- a/libhfuzz/persistent.c +++ b/libhfuzz/persistent.c @@ -24,13 +24,22 @@ __attribute__((visibility("default"))) __attribute__((used)) const char* const LIBHFUZZ_module_persistent = "LIBHFUZZ_module_persistent"; -__attribute__((weak)) int LLVMFuzzerTestOneInput(const uint8_t* buf, size_t len); -__attribute__((weak)) int LLVMFuzzerInitialize(int* argc, char*** argv); +__attribute__((weak)) int LLVMFuzzerInitialize( + int* argc HF_ATTR_UNUSED, char*** argv HF_ATTR_UNUSED) { + return 1; +} __attribute__((weak)) size_t LLVMFuzzerMutate( uint8_t* Data HF_ATTR_UNUSED, size_t Size HF_ATTR_UNUSED, size_t MaxSize HF_ATTR_UNUSED) { LOG_F("LLVMFuzzerMutate() is not supported in honggfuzz yet"); return 0; } +__attribute__((weak)) int LLVMFuzzerTestOneInput( + const uint8_t* buf HF_ATTR_UNUSED, size_t len HF_ATTR_UNUSED) { + LOG_F( + "Define 'int LLVMFuzzerTestOneInput(uint8_t * buf, size_t len)' in your " + "code to make it work"); + return 0; +} static const uint8_t* inputFile = NULL; __attribute__((constructor)) static void initializePersistent(void) { @@ -118,14 +127,7 @@ static int HonggfuzzRunFromFile(int argc, char** argv) { } int HonggfuzzMain(int argc, char** argv) { - if (LLVMFuzzerInitialize) { - LLVMFuzzerInitialize(&argc, &argv); - } - if (!LLVMFuzzerTestOneInput) { - LOG_F( - "Define 'int LLVMFuzzerTestOneInput(uint8_t * buf, size_t len)' in your " - "code to make it work"); - } + LLVMFuzzerInitialize(&argc, &argv); if (inputFile) { HonggfuzzPersistentLoop(); diff --git a/mac/arch.c b/mac/arch.c index 29fff1f15..89c0eb29b 100644 --- a/mac/arch.c +++ b/mac/arch.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,6 @@ #include #include #include -#include #include "fuzz.h" #include "honggfuzz.h"