diff options
author | Robert Swiecki <swiecki@google.com> | 2016-09-06 14:38:21 +0200 |
---|---|---|
committer | Robert Swiecki <swiecki@google.com> | 2016-09-06 14:38:21 +0200 |
commit | 94d54ff5098f44d6713e5e172aca48a418a93dff (patch) | |
tree | 80d8aecb4863d6fe26d1b3727f2df0f1d9ce3bdd | |
parent | 3cf9796207121fd59269316957fd5b37506f9d92 (diff) | |
download | honggfuzz-94d54ff5098f44d6713e5e172aca48a418a93dff.tar.gz |
Remove -I. from linux and posix builds
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | libhfuzz/compiler_instrument.c (renamed from libhfuzz/instrument_func.c) | 5 | ||||
-rw-r--r-- | libhfuzz/persistent.c (renamed from libhfuzz/persistent_mode.c) | 35 | ||||
-rw-r--r-- | libhfuzz/persistent_mode_main.c | 35 | ||||
-rw-r--r-- | linux/arch.c | 18 | ||||
-rw-r--r-- | linux/bfd.c | 10 | ||||
-rw-r--r-- | linux/perf.c | 12 | ||||
-rw-r--r-- | linux/pt.c | 8 | ||||
-rw-r--r-- | linux/pt.h | 2 | ||||
-rw-r--r-- | linux/ptrace_utils.c | 16 | ||||
-rw-r--r-- | linux/unwind.c | 6 | ||||
-rw-r--r-- | log.c | 2 | ||||
-rw-r--r-- | posix/arch.c | 14 |
13 files changed, 82 insertions, 85 deletions
@@ -34,7 +34,7 @@ MARCH ?= $(shell uname -m) ifeq ($(OS),Linux) ARCH := LINUX - ARCH_CFLAGS := -std=c11 -I. -I/usr/local/include -I/usr/include \ + ARCH_CFLAGS := -std=c11 -I/usr/local/include -I/usr/include \ -Wextra -Wno-initializer-overrides -Wno-override-init \ -Wno-unknown-warning-option -funroll-loops \ -D_FILE_OFFSET_BITS=64 @@ -111,7 +111,7 @@ else ifeq ($(OS),Darwin) else ARCH := POSIX ARCH_SRCS := $(wildcard posix/*.c) - ARCH_CFLAGS := -std=c11 -I. -I/usr/local/include -I/usr/include \ + ARCH_CFLAGS := -std=c11 -I/usr/local/include -I/usr/include \ -Wextra -Wno-initializer-overrides -Wno-override-init \ -Wno-unknown-warning-option -Wno-unknown-pragmas \ -U__STRICT_ANSI__ -funroll-loops diff --git a/libhfuzz/instrument_func.c b/libhfuzz/compiler_instrument.c index 06219cfc..e7be17f0 100644 --- a/libhfuzz/instrument_func.c +++ b/libhfuzz/compiler_instrument.c @@ -1,4 +1,4 @@ -#include "common.h" +#include "../common.h" #include <errno.h> #include <inttypes.h> @@ -11,14 +11,13 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> - #if defined(_HF_ARCH_LINUX) #include <asm/prctl.h> #include <sys/prctl.h> #include <sys/syscall.h> #endif // defined(_HF_ARCH_LINUX) -#include "util.h" +#include "../util.h" static feedback_t *feedback; static uint32_t my_thread_no = 0; diff --git a/libhfuzz/persistent_mode.c b/libhfuzz/persistent.c index 194a56c6..f8959f92 100644 --- a/libhfuzz/persistent_mode.c +++ b/libhfuzz/persistent.c @@ -10,7 +10,10 @@ #include <sys/types.h> #include <unistd.h> -#include "common.h" +#include "../common.h" + +int LLVMFuzzerTestOneInput(uint8_t * buf, size_t len) __attribute__ ((weak)); +int LLVMFuzzerInitialize(int *argc, char ***argv) __attribute__ ((weak)); static inline ssize_t readFromFd(int fd, uint8_t * buf, size_t len) { @@ -89,3 +92,33 @@ void HF_ITER(uint8_t ** buf_ptr, size_t * len_ptr) *buf_ptr = buf; *len_ptr = len; } + +/* + * Declare it 'weak', so it can be safely linked with regular binaries which + * implement their own main() + */ +__attribute__ ((weak)) +int main(int argc, char **argv) +{ + if (LLVMFuzzerInitialize) { + LLVMFuzzerInitialize(&argc, &argv); + } + if (LLVMFuzzerTestOneInput == NULL) { + fprintf(stderr, "Define 'int LLVMFuzzerTestOneInput(uint8_t * buf, size_t len)' in your " + "code to make it work\n"); + exit(1); + } + + for (;;) { + size_t len; + uint8_t *buf; + + HF_ITER(&buf, &len); + + int ret = LLVMFuzzerTestOneInput(buf, len); + if (ret != 0) { + fprintf(stderr, "LLVMFuzzerTestOneInput() returned '%d' instead of '0'\n", ret); + exit(1); + } + } +} diff --git a/libhfuzz/persistent_mode_main.c b/libhfuzz/persistent_mode_main.c deleted file mode 100644 index ffa8cf93..00000000 --- a/libhfuzz/persistent_mode_main.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <stdbool.h> -#include <stdlib.h> -#include <stdint.h> -#include <stdio.h> -#include <unistd.h> - -void HF_ITER(uint8_t ** buf, size_t * len); - -int LLVMFuzzerTestOneInput(uint8_t * buf, size_t len) __attribute__ ((weak)); -int LLVMFuzzerInitialize(int *argc, char ***argv) __attribute__ ((weak)); -int main(int argc, char **argv) __attribute__ ((weak)); - -int main(int argc, char **argv) -{ - if (LLVMFuzzerInitialize) { - LLVMFuzzerInitialize(&argc, &argv); - } - if (LLVMFuzzerTestOneInput == NULL) { - fprintf(stderr, "LLVMFuzzerTestOneInput not defined in your code\n"); - _exit(1); - } - - for (;;) { - size_t len; - uint8_t *buf; - - HF_ITER(&buf, &len); - - int ret = LLVMFuzzerTestOneInput(buf, len); - if (ret != 0) { - fprintf(stderr, "LLVMFuzzerTestOneInput() returned '%d'\n", ret); - _exit(1); - } - } -} diff --git a/linux/arch.c b/linux/arch.c index de262e55..8fac27c3 100644 --- a/linux/arch.c +++ b/linux/arch.c @@ -21,8 +21,8 @@ * */ -#include "common.h" -#include "arch.h" +#include "../common.h" +#include "../arch.h" #include <ctype.h> #include <errno.h> @@ -51,13 +51,13 @@ #include <sys/types.h> #include <sys/utsname.h> -#include "files.h" -#include "linux/perf.h" -#include "linux/ptrace_utils.h" -#include "log.h" -#include "sancov.h" -#include "subproc.h" -#include "util.h" +#include "../files.h" +#include "../linux/perf.h" +#include "../linux/ptrace_utils.h" +#include "../log.h" +#include "../sancov.h" +#include "../subproc.h" +#include "../util.h" /* Common sanitizer flags */ #if _HF_MONITOR_SIGABRT diff --git a/linux/bfd.c b/linux/bfd.c index df5cd8a2..9d2893f6 100644 --- a/linux/bfd.c +++ b/linux/bfd.c @@ -21,8 +21,8 @@ * */ -#include "common.h" -#include "linux/bfd.h" +#include "../common.h" +#include "bfd.h" #include <bfd.h> #include <dis-asm.h> @@ -36,9 +36,9 @@ #include <inttypes.h> #include <unistd.h> -#include "files.h" -#include "log.h" -#include "util.h" +#include "../files.h" +#include "../log.h" +#include "../util.h" typedef struct { bfd *bfdh; diff --git a/linux/perf.c b/linux/perf.c index 492c818d..2136ba53 100644 --- a/linux/perf.c +++ b/linux/perf.c @@ -21,8 +21,8 @@ * */ -#include "common.h" -#include "linux/perf.h" +#include "../common.h" +#include "perf.h" #include <asm/mman.h> #include <errno.h> @@ -41,10 +41,10 @@ #include <sys/syscall.h> #include <unistd.h> -#include "files.h" -#include "linux/pt.h" -#include "log.h" -#include "util.h" +#include "../files.h" +#include "../log.h" +#include "../util.h" +#include "pt.h" #define _HF_PERF_MAP_SZ (1024 * 1024) #define _HF_PERF_AUX_SZ (1024 * 1024 * 8) @@ -21,14 +21,14 @@ * */ -#include "common.h" -#include "linux/pt.h" +#include "../common.h" +#include "pt.h" #include <linux/perf_event.h> #include <inttypes.h> -#include "log.h" -#include "util.h" +#include "../log.h" +#include "../util.h" #ifdef _HF_LINUX_INTEL_PT_LIB @@ -24,7 +24,7 @@ #ifndef _HF_LINUX_PT_H_ #define _HF_LINUX_PT_H_ -#include "common.h" +#include "../common.h" #include <linux/perf_event.h> #include <stdint.h> diff --git a/linux/ptrace_utils.c b/linux/ptrace_utils.c index 45c34901..8a1d19fa 100644 --- a/linux/ptrace_utils.c +++ b/linux/ptrace_utils.c @@ -21,7 +21,7 @@ * */ -#include "common.h" +#include "../common.h" #include "ptrace_utils.h" #include <ctype.h> @@ -49,13 +49,13 @@ #include <time.h> #include <unistd.h> -#include "files.h" -#include "linux/bfd.h" -#include "linux/unwind.h" -#include "log.h" -#include "sancov.h" -#include "subproc.h" -#include "util.h" +#include "../files.h" +#include "../log.h" +#include "../sancov.h" +#include "../subproc.h" +#include "../util.h" +#include "bfd.h" +#include "unwind.h" #if defined(__ANDROID__) #include "capstone.h" diff --git a/linux/unwind.c b/linux/unwind.c index a8bb40e1..33a7c77b 100644 --- a/linux/unwind.c +++ b/linux/unwind.c @@ -21,13 +21,13 @@ * */ -#include "common.h" -#include "linux/unwind.h" +#include "../common.h" +#include "unwind.h" #include <endian.h> #include <libunwind-ptrace.h> -#include "log.h" +#include "../log.h" /* * WARNING: Ensure that _UPT-info structs are not shared between threads @@ -36,7 +36,7 @@ #include <time.h> #include <unistd.h> -#include <util.h> +#include "util.h" #if defined(_HF_ARCH_LINUX) #include <sys/syscall.h> diff --git a/posix/arch.c b/posix/arch.c index 4d2b5a46..da02d8df 100644 --- a/posix/arch.c +++ b/posix/arch.c @@ -21,8 +21,8 @@ * */ -#include "common.h" -#include "arch.h" +#include "../common.h" +#include "../arch.h" #include <poll.h> #include <ctype.h> @@ -41,11 +41,11 @@ #include <time.h> #include <unistd.h> -#include "files.h" -#include "log.h" -#include "sancov.h" -#include "subproc.h" -#include "util.h" +#include "../files.h" +#include "../log.h" +#include "../sancov.h" +#include "../subproc.h" +#include "../util.h" /* *INDENT-OFF* */ struct { |