From d3bd576c469a06bc1cef1be1149bf1de03ae3179 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 26 Jul 2018 10:01:46 +0200 Subject: [PATCH] fuzz: Add fuzzer for identification_t --- fuzz/.gitignore | 1 + fuzz/Makefile.am | 5 ++++- fuzz/fuzz_ids.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 fuzz/fuzz_ids.c diff --git a/fuzz/.gitignore b/fuzz/.gitignore index 765d23ae2..0927874fb 100644 --- a/fuzz/.gitignore +++ b/fuzz/.gitignore @@ -1,4 +1,5 @@ fuzz_certs fuzz_crls +fuzz_ids fuzz_pa_tnc fuzz_pb_tnc diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am index de0a2604d..55ead622e 100644 --- a/fuzz/Makefile.am +++ b/fuzz/Makefile.am @@ -25,7 +25,7 @@ pb_tnc_ldflags = \ $(top_builddir)/src/libtncif/.libs/libtncif.a \ $(fuzz_ldflags) -FUZZ_TARGETS=fuzz_certs fuzz_crls fuzz_pa_tnc fuzz_pb_tnc +FUZZ_TARGETS=fuzz_certs fuzz_crls fuzz_ids fuzz_pa_tnc fuzz_pb_tnc all-local: $(FUZZ_TARGETS) @@ -37,6 +37,9 @@ fuzz_certs: fuzz_certs.c ${libfuzzer} fuzz_crls: fuzz_crls.c ${libfuzzer} $(CC) $(AM_CPPFLAGS) $(CFLAGS) -o $@ $< $(fuzz_ldflags) +fuzz_ids: fuzz_ids.c ${libfuzzer} + $(CC) $(AM_CPPFLAGS) $(CFLAGS) -o $@ $< $(fuzz_ldflags) + fuzz_pa_tnc: fuzz_pa_tnc.c ${libfuzzer} $(CC) $(AM_CPPFLAGS) $(CFLAGS) -o $@ $< $(pa_tnc_ldflags) diff --git a/fuzz/fuzz_ids.c b/fuzz/fuzz_ids.c new file mode 100644 index 000000000..8840c6e25 --- /dev/null +++ b/fuzz/fuzz_ids.c @@ -0,0 +1,33 @@ +/* + * 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 . + * + * 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 +#include + +int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) +{ + identification_t *id; + chunk_t chunk; + + dbg_default_set_level(-1); + library_init(NULL, "fuzz_ids"); + + chunk = chunk_create((u_char*)buf, len); + id = identification_create_from_data(chunk); + DESTROY_IF(id); + + library_deinit(); + return 0; +}