summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2017-04-03 20:05:07 +0200
committerDavid Tardon <dtardon@redhat.com>2017-04-03 20:05:07 +0200
commitf4a06f4c33601f81ea80374f7b877c46e18ca05e (patch)
tree55be3ebbd6509411e2f7a0fb87d9f1adad788bbd
parent70cca7f8416b149c9d6e838fa40bbbd433d6812b (diff)
use C++ for fuzzer
-rw-r--r--configure.ac3
-rw-r--r--fuzz/Makefile.am8
-rw-r--r--fuzz/tagfuzzer.cpp (renamed from fuzz/tagfuzzer.c)20
3 files changed, 13 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac
index b09828d..57f7023 100644
--- a/configure.ac
+++ b/configure.ac
@@ -372,6 +372,9 @@ AC_ARG_ENABLE([fuzzers],
[enable_fuzzers="$enableval"],
[enable_fuzzers=no]
)
+if test "x$enable_fuzzers" = "xyes"; then
+ AC_PROG_CXX
+fi
AM_CONDITIONAL(BUILD_FUZZERS, [test "x$enable_fuzzers" = "xyes"])
dnl ======================================================================
diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am
index 29e9388..8cb3166 100644
--- a/fuzz/Makefile.am
+++ b/fuzz/Makefile.am
@@ -1,6 +1,6 @@
noinst_PROGRAMS = tagfuzzer
-AM_CFLAGS = \
+AM_CXXFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/liblangtag \
$(NULL)
@@ -8,11 +8,9 @@ AM_CFLAGS = \
tagfuzzer_LDADD = \
$(top_builddir)/liblangtag/liblangtag.la \
@MODULE_LIBS@ \
- -lFuzzingEngine \
- $(FUZZER_LIBS) \
- $(NULL)
+ -lFuzzingEngine
tagfuzzer_SOURCES = \
- tagfuzzer.c
+ tagfuzzer.cpp
-include $(top_srcdir)/git.mk
diff --git a/fuzz/tagfuzzer.c b/fuzz/tagfuzzer.cpp
index 6f220ce..2dcc9bb 100644
--- a/fuzz/tagfuzzer.c
+++ b/fuzz/tagfuzzer.cpp
@@ -11,27 +11,21 @@
* License, as specified in the README file.
*/
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdint>
+#include <cstdlib>
+#include <string>
#include <liblangtag/langtag.h>
-int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
-
-int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
+ const std::string s(reinterpret_cast<const char *>(data), size);
+
lt_tag_t *tag = 0;
lt_error_t *error = 0;
- char *string = 0;
-
- string = malloc(size + 1);
- memcpy(string, data, size);
- string[size] = 0;
- lt_tag_parse(tag, string, &error);
+ lt_tag_parse(tag, s.c_str(), &error);
- free(string);
if (tag)
lt_tag_unref(tag);
if (error)