From 8057239354cccd9b1954e99a06c4eb37f12383a0 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Wed, 11 Dec 2019 16:37:38 -0500 Subject: [PATCH] lib: add fuzzing stuff in libfrr Signed-off-by: Quentin Young --- lib/fuzz.h | 26 ++++++++++++++++++++++++++ lib/zebra.h | 9 ++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/fuzz.h diff --git a/lib/fuzz.h b/lib/fuzz.h new file mode 100644 index 0000000000..04c48c808a --- /dev/null +++ b/lib/fuzz.h @@ -0,0 +1,26 @@ +/* + * Utilities for fuzzing frr. + */ +#ifndef __FUZZ_H__ +#define __FUZZ_H__ + +#include +#include +#include + +static inline int frrfuzz_read_input(uint8_t **input) +{ + fseek(stdin, 0, SEEK_END); + long fsize = ftell(stdin); + if (fsize < 0) + return 0; + + *input = (uint8_t *)malloc(fsize); + + fseek(stdin, 0, SEEK_SET); + int r = fread(*input, 1, fsize, stdin); + + return r; +} + +#endif /* __FUZZ_H__ */ diff --git a/lib/zebra.h b/lib/zebra.h index 0a5e652bb1..332a8bd758 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -18,10 +18,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#define FUZZING 1 #ifndef _ZEBRA_H #define _ZEBRA_H +#define FUZZING 1 + #ifdef HAVE_CONFIG_H #include "config.h" #endif /* HAVE_CONFIG_H */ @@ -76,6 +77,12 @@ #include #endif + +#ifdef FUZZING +#include "fuzz.h" +#endif + + /* machine dependent includes */ #ifdef HAVE_LINUX_VERSION_H #include -- 2.39.5