fuzzing: Add fuzzer for CRL parsing

This commit is contained in:
Tobias Brunner 2018-02-20 17:51:55 +01:00
parent 29b983309f
commit bd6e4bbe68
3 changed files with 46 additions and 2 deletions

3
fuzz/.gitignore vendored
View File

@ -1 +1,2 @@
fuzz_certs
fuzz_certs
fuzz_crls

View File

@ -8,7 +8,7 @@ fuzz_ldflags = ${libfuzzer} \
-Wl,-Bstatic -lgmp -Wl,-Bdynamic \
@FUZZING_LDFLAGS@
FUZZ_TARGETS=fuzz_certs
FUZZ_TARGETS=fuzz_certs fuzz_crls
all-local: $(FUZZ_TARGETS)
@ -17,6 +17,9 @@ CLEANFILES=$(FUZZ_TARGETS)
fuzz_certs: fuzz_certs.c ${libfuzzer}
$(CC) $(AM_CPPFLAGS) $(CFLAGS) -o $@ $< $(fuzz_ldflags)
fuzz_crls: fuzz_crls.c ${libfuzzer}
$(CC) $(AM_CPPFLAGS) $(CFLAGS) -o $@ $< $(fuzz_ldflags)
noinst_LIBRARIES = libFuzzerLocal.a
libFuzzerLocal_a_SOURCES = libFuzzerLocal.c
libFuzzerLocal_a_LIBADD = $(top_builddir)/src/libstrongswan/libstrongswan.la

40
fuzz/fuzz_crls.c Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2018 Tobias Brunner
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <library.h>
#include <utils/debug.h>
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
{
certificate_t *cert;
chunk_t chunk;
dbg_default_set_level(-1);
library_init(NULL, "fuzz_crls");
plugin_loader_add_plugindirs(PLUGINDIR, PLUGINS);
if (!lib->plugins->load(lib->plugins, PLUGINS))
{
return 1;
}
chunk = chunk_create((u_char*)buf, len);
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509_CRL,
BUILD_BLOB, chunk, BUILD_END);
DESTROY_IF(cert);
lib->plugins->unload(lib->plugins);
library_deinit();
return 0;
}