summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2017-03-31 19:04:32 +0200
committerDavid Tardon <dtardon@redhat.com>2017-03-31 19:04:32 +0200
commit6ca823ad65337c5df657c671ed31fbfe9cf43e79 (patch)
treef86c1dc4b28a8a7ee48d62c6ae61307d565c1994
parentc5b2db4b8b14b04204d8feeaf5d38b80afa401e7 (diff)
add fuzzing driver for oss-fuzz
Change-Id: I1476b646c05dbc7128353ae6ae6a999ce4c89627
-rw-r--r--configure.ac17
-rw-r--r--src/Makefile.am4
-rw-r--r--src/fuzz/.gitignore8
-rw-r--r--src/fuzz/Makefile.am17
-rw-r--r--src/fuzz/fhfuzzer.cpp27
5 files changed, 71 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 65a4ca5..3508c90 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,7 +62,19 @@ AC_ARG_ENABLE([tools],
[enable_tools="$enableval"],
[enable_tools=yes]
)
-AS_IF([test "x$enable_tools" = "xyes"], [
+AM_CONDITIONAL(BUILD_TOOLS, [test "x$enable_tools" = "xyes"])
+
+# =======
+# 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"])
+
+AS_IF([test "x$enable_tools" = "xyes" -o "x$enable_fuzzers" = "xyes"], [
PKG_CHECK_MODULES([REVENGE_STREAM],[
librevenge-stream-0.0
])
@@ -74,7 +86,6 @@ AC_SUBST([REVENGE_STREAM_CFLAGS])
AC_SUBST([REVENGE_STREAM_LIBS])
AC_SUBST([REVENGE_GENERATORS_CFLAGS])
AC_SUBST([REVENGE_GENERATORS_LIBS])
-AM_CONDITIONAL(BUILD_TOOLS, [test "x$enable_tools" = "xyes"])
# =========
# Find zlib
@@ -317,6 +328,7 @@ src/conv/svg/Makefile
src/conv/svg/fh2svg.rc
src/conv/text/Makefile
src/conv/text/fh2text.rc
+src/fuzz/Makefile
src/lib/Makefile
src/lib/libfreehand.rc
inc/Makefile
@@ -337,6 +349,7 @@ AC_MSG_NOTICE([
Build configuration:
debug: ${enable_debug}
docs: ${build_docs}
+ fuzzers: ${enable_fuzzers}
tools: ${enable_tools}
werror: ${enable_werror}
==============================================================================
diff --git a/src/Makefile.am b/src/Makefile.am
index 64fd45e..c83c78c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,3 +3,7 @@ SUBDIRS = lib
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..3bb67ff
--- /dev/null
+++ b/src/fuzz/Makefile.am
@@ -0,0 +1,17 @@
+noinst_PROGRAMS = fhfuzzer
+
+AM_CXXFLAGS = -I$(top_srcdir)/inc \
+ $(REVENGE_GENERATORS_CFLAGS) \
+ $(REVENGE_CFLAGS) \
+ $(REVENGE_STREAM_CFLAGS) \
+ $(DEBUG_CXXFLAGS)
+
+fhfuzzer_LDADD = \
+ $(top_builddir)/src/lib/libfreehand-@FH_MAJOR_VERSION@.@FH_MINOR_VERSION@.la \
+ $(REVENGE_GENERATORS_LIBS) \
+ $(REVENGE_LIBS) \
+ $(REVENGE_STREAM_LIBS) \
+ -lFuzzingEngine
+
+fhfuzzer_SOURCES = \
+ fhfuzzer.cpp
diff --git a/src/fuzz/fhfuzzer.cpp b/src/fuzz/fhfuzzer.cpp
new file mode 100644
index 0000000..4693e4c
--- /dev/null
+++ b/src/fuzz/fhfuzzer.cpp
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libfreehand 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 <cstdint>
+#include <cstdlib>
+
+#include <libfreehand/libfreehand.h>
+
+#include <librevenge-generators/librevenge-generators.h>
+
+#include <librevenge-stream/librevenge-stream.h>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ librevenge::RVNGStringStream input(data, size);
+ librevenge::RVNGRawDrawingGenerator generator(true);
+ libfreehand::FreeHandDocument::parse(&input, &generator);
+ return 0;
+}
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */