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 */