Move ossfuzz directory and use Makefile.am
This commit is contained in:
parent
100e5549b6
commit
24cc9dd078
@ -21,4 +21,4 @@ script:
|
||||
- if [ "$JANSSON_BUILD_METHOD" = "autotools" ]; then autoreconf -f -i && CFLAGS=-Werror ./configure && make check; fi
|
||||
- if [ "$JANSSON_BUILD_METHOD" = "cmake" ]; then mkdir build && cd build && cmake $JANSSON_CMAKE_OPTIONS .. && cmake --build . && ctest --output-on-failure; fi
|
||||
- if [ "$JANSSON_BUILD_METHOD" = "coverage" ]; then mkdir build && cd build && cmake $JANSSON_CMAKE_OPTIONS .. && cmake --build . && cmake --build . --target coveralls; fi
|
||||
- if [ "$JANSSON_BUILD_METHOD" = "fuzzer" ]; then ./ossfuzz/travisoss.sh; fi
|
||||
- if [ "$JANSSON_BUILD_METHOD" = "fuzzer" ]; then ./test/ossfuzz/travisoss.sh; fi
|
||||
|
12
Makefile.am
12
Makefile.am
@ -8,15 +8,3 @@ dvi:
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = jansson.pc
|
||||
|
||||
|
||||
# Add fuzzing support
|
||||
LIB_FUZZING_ENGINE ?= standaloneengine.o
|
||||
|
||||
ossfuzz/%.o: ossfuzz/%.cc
|
||||
$(CXX) -c -Isrc $(CXXFLAGS) $< -o $@
|
||||
|
||||
.PHONY: json_load_fuzzer
|
||||
json_load_fuzzer: ossfuzz/json_load_fuzzer.o src/.libs/libjansson.a
|
||||
$(CXX) -c $(CXXFLAGS) ossfuzz/standaloneengine.cc -o standaloneengine.o
|
||||
$(CXX) $(CXXFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
|
||||
|
15
configure.ac
15
configure.ac
@ -9,6 +9,7 @@ AC_CONFIG_HEADERS([jansson_private_config.h])
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
AC_PROG_LIBTOOL
|
||||
AM_CONDITIONAL([GCC], [test x$GCC = xyes])
|
||||
|
||||
@ -136,6 +137,19 @@ fi
|
||||
AS_IF([test "x$with_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions])
|
||||
AC_SUBST(JSON_BSYMBOLIC_LDFLAGS)
|
||||
|
||||
|
||||
AC_ARG_ENABLE([ossfuzzers],
|
||||
[AS_HELP_STRING([--enable-ossfuzzers],
|
||||
[Whether to generate the fuzzers for OSS-Fuzz])],
|
||||
[have_ossfuzzers=yes], [have_ossfuzzers=no])
|
||||
AM_CONDITIONAL([USE_OSSFUZZERS], [test "x$have_ossfuzzers" = "xyes"])
|
||||
|
||||
|
||||
AC_SUBST([LIB_FUZZING_ENGINE])
|
||||
AM_CONDITIONAL([USE_OSSFUZZ_FLAG], [test "x$LIB_FUZZING_ENGINE" = "x-fsanitize=fuzzer"])
|
||||
AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "x$LIB_FUZZING_ENGINE"])
|
||||
|
||||
|
||||
if test x$GCC = xyes; then
|
||||
AC_MSG_CHECKING(for -Wno-format-truncation)
|
||||
wnoformat_truncation="-Wno-format-truncation"
|
||||
@ -156,6 +170,7 @@ AC_CONFIG_FILES([
|
||||
src/jansson_config.h
|
||||
test/Makefile
|
||||
test/bin/Makefile
|
||||
test/ossfuzz/Makefile
|
||||
test/suites/Makefile
|
||||
test/suites/api/Makefile
|
||||
])
|
||||
|
@ -1,11 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "jansson.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
json_error_t error;
|
||||
auto jobj = json_loadb(reinterpret_cast<const char *>(data), size, 0, &error);
|
||||
if (jobj)
|
||||
json_decref(jobj);
|
||||
return 0;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
SUBDIRS = bin suites
|
||||
SUBDIRS = bin suites ossfuzz
|
||||
EXTRA_DIST = scripts run-suites
|
||||
|
||||
TESTS = run-suites
|
||||
|
1
test/ossfuzz/.gitignore
vendored
Normal file
1
test/ossfuzz/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
json_load_dump_fuzzer
|
32
test/ossfuzz/Makefile.am
Normal file
32
test/ossfuzz/Makefile.am
Normal file
@ -0,0 +1,32 @@
|
||||
AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src
|
||||
LDADD = $(top_builddir)/src/libjansson.la
|
||||
|
||||
if USE_OSSFUZZ_FLAG
|
||||
FUZZ_FLAG = $(LIB_FUZZING_ENGINE)
|
||||
else
|
||||
if USE_OSSFUZZ_STATIC
|
||||
LDADD += $(LIB_FUZZING_ENGINE)
|
||||
FUZZ_FLAG =
|
||||
else
|
||||
LDADD += libstandaloneengine.a
|
||||
FUZZ_FLAG =
|
||||
endif
|
||||
endif
|
||||
|
||||
noinst_PROGRAMS =
|
||||
noinst_LIBRARIES =
|
||||
|
||||
if USE_OSSFUZZERS
|
||||
noinst_PROGRAMS += \
|
||||
json_load_dump_fuzzer
|
||||
|
||||
noinst_LIBRARIES += \
|
||||
libstandaloneengine.a
|
||||
endif
|
||||
|
||||
json_load_dump_fuzzer_SOURCES = json_load_dump_fuzzer.cc testinput.h
|
||||
json_load_dump_fuzzer_CXXFLAGS = $(AM_CXXFLAGS) $(FUZZ_FLAG)
|
||||
json_load_dump_fuzzer_LDFLAGS = $(AM_LDFLAGS) -static
|
||||
|
||||
libstandaloneengine_a_SOURCES = standaloneengine.cc
|
||||
libstandaloneengine_a_CXXFLAGS = $(AM_CXXFLAGS)
|
47
test/ossfuzz/json_load_dump_fuzzer.cc
Normal file
47
test/ossfuzz/json_load_dump_fuzzer.cc
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "jansson.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
json_error_t error;
|
||||
|
||||
if (size < sizeof(size_t) + sizeof(size_t))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Use the first sizeof(size_t) bytes as load flags.
|
||||
size_t load_flags = *(const size_t*)data;
|
||||
data += sizeof(size_t);
|
||||
size -= sizeof(size_t);
|
||||
|
||||
// Use the next sizeof(size_t) bytes as dump flags.
|
||||
size_t dump_flags = *(const size_t*)data;
|
||||
data += sizeof(size_t);
|
||||
size -= sizeof(size_t);
|
||||
|
||||
// Attempt to load the remainder of the data with the given load flags.
|
||||
const char* text = reinterpret_cast<const char *>(data);
|
||||
json_t* jobj = json_loadb(text, size, load_flags, &error);
|
||||
|
||||
if (jobj == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Attempt to dump the loaded json object with the given dump flags.
|
||||
char* out = json_dumps(jobj, dump_flags);
|
||||
if (out)
|
||||
{
|
||||
free(out);
|
||||
}
|
||||
|
||||
if (jobj)
|
||||
{
|
||||
json_decref(jobj);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -20,9 +20,8 @@ apt-get -y install automake libtool
|
||||
|
||||
# Compile the fuzzer.
|
||||
autoreconf -i
|
||||
./configure
|
||||
./configure --enable-ossfuzzers
|
||||
make
|
||||
make json_load_fuzzer
|
||||
|
||||
# Copy the fuzzer to the output directory.
|
||||
cp -v json_load_fuzzer $OUT/
|
||||
cp -v test/ossfuzz/json_load_dump_fuzzer $OUT/
|
Loading…
Reference in New Issue
Block a user