More fuzzer improvements

This commit is contained in:
Tim Rühsen 2017-06-14 12:45:05 +02:00
parent 43f460d4c5
commit f304dbe324
3 changed files with 32 additions and 11 deletions

View File

@ -31,12 +31,16 @@ fuzz-coverage: $(PSL_TESTS)
oss-fuzz:
if test "$$OUT" != ""; then \
if $$(ldd ../src/.libs/libpsl.so|grep -q libidn2); then XLIBS="-lidn2 -lunistring"; \
elif $$(ldd ../src/.libs/libpsl.so|grep -q libidn); then XLIBS="-lidn -lunistring"; \
elif $$(ldd ../src/.libs/libpsl.so|grep -q libicu); then XLIBS="-licuuc -licudata"; \
else XLIBS=""; fi; \
for ccfile in *_fuzzer.c; do \
fuzzer=$$(basename $$ccfile .c); \
$$CXX $$CXXFLAGS -I$(top_srcdir)/include -I$(top_srcdir) \
"$${fuzzer}.c" -o "$${fuzzer}" \
../src/.libs/libpsl.a $${LIB_FUZZING_ENGINE} -Wl,-Bstatic \
-lidn2 -lunistring \
$$XLIBS \
-Wl,-Bdynamic; \
done; \
fi

View File

@ -29,11 +29,16 @@
#include <stdlib.h> // malloc, free
#include <string.h> // memcpy
#if defined(WITH_LIBICU)
#include <unicode/uclean.h>
#endif
#include "libpsl.h"
#include "fuzzer.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
static int first_run = 1;
char *domain = (char *) malloc(size + 1), *res;
int rc;
@ -46,7 +51,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
psl_ctx_t *psl;
psl = (psl_ctx_t *) psl_builtin();
psl_is_public_suffix(NULL, domain);
psl_is_public_suffix(psl, domain);
psl_is_public_suffix2(psl, domain, PSL_TYPE_PRIVATE);
psl_is_public_suffix2(psl, domain, PSL_TYPE_ICANN);
@ -65,15 +69,23 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
psl_free(psl);
psl_check_version_number(1);
psl_get_version();
psl_dist_filename();
psl_builtin_outdated();
psl_builtin_filename();
psl_builtin_sha1sum();
psl_builtin_file_time();
if (first_run) {
psl_is_public_suffix(NULL, domain);
psl_check_version_number(1);
psl_get_version();
psl_dist_filename();
psl_builtin_outdated();
psl_builtin_filename();
psl_builtin_sha1sum();
psl_builtin_file_time();
first_run = 0;
}
free(domain);
#if defined(WITH_LIBICU)
u_cleanup(); // free all library internal memory to avoid memory leaks being reported
#endif
return 0;
}

View File

@ -32,11 +32,16 @@ fuzzer=$1
workers=$(($(nproc) - 1))
jobs=$workers
if $(ldd ../src/.libs/libpsl.so|grep -q libidn2); then XLIBS="-lidn2 -lunistring"; \
elif $(ldd ../src/.libs/libpsl.so|grep -q libidn); then XLIBS="-lidn -lunistring"; \
elif $(ldd ../src/.libs/libpsl.so|grep -q libicu); then XLIBS="-licuuc -licudata"; \
else XLIBS=""; fi; \
clang-5.0 \
$CFLAGS -I../include -I.. \
$CFLAGS -Og -g -I../include -I.. \
${fuzzer}.c -o ${fuzzer} \
-Wl,-Bstatic ../src/.libs/libpsl.a -lFuzzer \
-Wl,-Bdynamic -lidn2 -lunistring -lclang-5.0 -lstdc++
-Wl,-Bdynamic $XLIBS -lclang-5.0 -lstdc++
# create directory for NEW test corpora (covering new areas of code)
mkdir -p ${fuzzer}.new