From f3e671591e6938e27aa15ba52f258617456a8fac Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 24 Feb 2019 18:52:54 +0200 Subject: [PATCH] tests: libFuzzer integration for test-json and test-x509 Allow these test tools to be used with libFuzzer in addition to afl-fuzz. Signed-off-by: Jouni Malinen --- tests/Makefile | 9 +++++++++ tests/README | 9 +++++++++ tests/test-json.c | 50 +++++++++++++++++++++++++++++++++-------------- tests/test-x509.c | 13 +++++++++++- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 3b5c86fba..95855aa3b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,6 +5,15 @@ TESTS=test-base64 test-md4 test-milenage \ all: $(TESTS) +ifdef LIBFUZZER +CC=clang +CFLAGS = -MMD -O2 -Wall -g +CFLAGS += -fsanitize=fuzzer,address,signed-integer-overflow,unsigned-integer-overflow +CFLAGS += -DTEST_LIBFUZZER +LDFLAGS += -fsanitize=fuzzer,address,signed-integer-overflow,unsigned-integer-overflow +TEST_FUZZ=y +endif + ifndef CC CC=gcc endif diff --git a/tests/README b/tests/README index 68f6023d0..b11e07b08 100644 --- a/tests/README +++ b/tests/README @@ -45,6 +45,15 @@ cat > json-examples/1.json < json-examples/1.json < + * Copyright (c) 2006-2019, Jouni Malinen * * This software may be distributed under the terms of the BSD license. * See README for more details. @@ -12,6 +12,16 @@ #include "tls/x509v3.h" +#ifdef TEST_LIBFUZZER +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + struct x509_certificate *cert; + + cert = x509_certificate_parse(data, size); + x509_certificate_free(cert); + return 0; +} +#else /* TEST_LIBFUZZER */ int main(int argc, char *argv[]) { FILE *f; @@ -34,3 +44,4 @@ int main(int argc, char *argv[]) return 0; } +#endif /* TEST_LIBFUZZER */