From 2f1be67cec55af6fc694ec932a4a3f2c1d671af7 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Thu, 30 Mar 2017 20:08:34 +0200 Subject: create fuzzing driver for oss-fuzz Change-Id: I9f778f52de5936f0555ec32d6deea8981dd6dc93 --- configure.ac | 16 ++++++++++++++-- src/Makefile.am | 4 ++++ src/fuzz/.gitignore | 8 ++++++++ src/fuzz/Makefile.am | 17 +++++++++++++++++ src/fuzz/vsdfuzzer.cpp | 27 +++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/fuzz/.gitignore create mode 100644 src/fuzz/Makefile.am create mode 100644 src/fuzz/vsdfuzzer.cpp diff --git a/configure.ac b/configure.ac index 79a65e1..5a77a46 100644 --- a/configure.ac +++ b/configure.ac @@ -100,6 +100,16 @@ AC_ARG_ENABLE([tools], [enable_tools=yes] ) +# ======= +# Fuzzers +# ======= +AC_ARG_ENABLE([fuzzers], + [AS_HELP_STRING([--enable-fuzzers], [Build fuzzer(s)])], + [enable_fuzzers="$enableval"], + [enable_fuzzers=no] +) +AM_CONDITIONAL(BUILD_FUZZERS, [test "x$enable_fuzzers" = "xyes"]) + # ========== # Unit tests # ========== @@ -109,7 +119,7 @@ AC_ARG_ENABLE([tests], [enable_tests=yes] ) -AS_IF([test "x$enable_tools" = "xyes" -o "x$enable_tests" = "xyes"], [ +AS_IF([test "x$enable_tools" = "xyes" -o "x$enable_tests" = "xyes" -o "x$enable_fuzzers" = "xyes"], [ PKG_CHECK_MODULES([REVENGE_STREAM],[ librevenge-stream-0.0 ]) @@ -123,7 +133,7 @@ AS_IF([test "x$enable_tests" = "xyes"], [ AC_SUBST([CPPUNIT_CFLAGS]) AC_SUBST([CPPUNIT_LIBS]) -AS_IF([test "x$enable_tools" = "xyes"], [ +AS_IF([test "x$enable_tools" = "xyes" -o "x$enable_fuzzers" = "xyes"], [ PKG_CHECK_MODULES([REVENGE_GENERATORS],[ librevenge-generators-0.0 ]) @@ -338,6 +348,7 @@ src/conv/svg/vss2xhtml.rc src/conv/text/Makefile src/conv/text/vsd2text.rc src/conv/text/vss2text.rc +src/fuzz/Makefile src/lib/Makefile src/lib/libvisio.rc src/test/Makefile @@ -359,6 +370,7 @@ AC_MSG_NOTICE([ Build configuration: debug: ${enable_debug} docs: ${build_docs} + fuzzers: ${enable_fuzzers} tests: ${enable_tests} tools: ${enable_tools} werror: ${enable_werror} diff --git a/src/Makefile.am b/src/Makefile.am index c9dad75..a6eb477 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,3 +7,7 @@ endif if BUILD_TOOLS SUBDIRS += conv endif + +if BUILD_FUZZERS +SUBDIRS += fuzz +endif diff --git a/src/fuzz/.gitignore b/src/fuzz/.gitignore new file mode 100644 index 0000000..df86dfd --- /dev/null +++ b/src/fuzz/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +*.lo +*.la +*.o +Makefile +Makefile.in +*fuzzer diff --git a/src/fuzz/Makefile.am b/src/fuzz/Makefile.am new file mode 100644 index 0000000..168b038 --- /dev/null +++ b/src/fuzz/Makefile.am @@ -0,0 +1,17 @@ +noinst_PROGRAMS = vsdfuzzer + +AM_CXXFLAGS = -I$(top_srcdir)/inc \ + $(REVENGE_GENERATORS_CFLAGS) \ + $(REVENGE_CFLAGS) \ + $(REVENGE_STREAM_CFLAGS) \ + $(DEBUG_CXXFLAGS) + +vsdfuzzer_LDADD = \ + $(top_builddir)/src/lib/libvisio-@VSD_MAJOR_VERSION@.@VSD_MINOR_VERSION@.la \ + $(REVENGE_GENERATORS_LIBS) \ + $(REVENGE_LIBS) \ + $(REVENGE_STREAM_LIBS) \ + -lFuzzingEngine + +vsdfuzzer_SOURCES = \ + vsdfuzzer.cpp diff --git a/src/fuzz/vsdfuzzer.cpp b/src/fuzz/vsdfuzzer.cpp new file mode 100644 index 0000000..f5b8f7e --- /dev/null +++ b/src/fuzz/vsdfuzzer.cpp @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * This file is part of the libvisio project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include + +#include + +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + librevenge::RVNGStringStream input(data, size); + librevenge::RVNGRawDrawingGenerator generator(true); + libvisio::VisioDocument::parse(&input, &generator); + return 0; +} + +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ -- cgit v1.2.3