Skip to content

Commit

Permalink
make hfuzz-cc workable under macos
Browse files Browse the repository at this point in the history
  • Loading branch information
robertswiecki committed Feb 21, 2018
1 parent d7859cf commit df02b9d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions hfuzz_cc/hfuzz-cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion honggfuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
22 changes: 12 additions & 10 deletions libhfuzz/persistent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion mac/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -41,7 +42,6 @@
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <poll.h>

#include "fuzz.h"
#include "honggfuzz.h"
Expand Down

0 comments on commit df02b9d

Please sign in to comment.