Annotation of embedaddon/strongswan/fuzz/libFuzzerLocal.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2017 Tobias Brunner
3: * HSR Hochschule fuer Technik Rapperswil
4: *
5: * This program is free software; you can redistribute it and/or modify it
6: * under the terms of the GNU General Public License as published by the
7: * Free Software Foundation; either version 2 of the License, or (at your
8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9: *
10: * This program is distributed in the hope that it will be useful, but
11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: * for more details.
14: */
15:
16: #include <stdio.h>
17: #include <stdlib.h>
18: #include <errno.h>
19: #include <library.h>
20:
21: extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
22: __attribute__((weak)) extern int LLVMFuzzerInitialize(int *argc, char ***argv);
23:
24: /**
25: * This is a simple driver for the fuzz targets to verify test inputs outside
26: * of OSS-Fuzz.
27: *
28: * Failures will usually cause crashes.
29: */
30: int main(int argc, char **argv)
31: {
32: chunk_t *data;
33: int i, res = 0;
34:
35: fprintf(stderr, "%s: running %d inputs\n", argv[0], argc - 1);
36: if (LLVMFuzzerInitialize)
37: {
38: LLVMFuzzerInitialize(&argc, &argv);
39: }
40: for (i = 1; i < argc; i++)
41: {
42: fprintf(stderr, "running: %s\n", argv[i]);
43: data = chunk_map(argv[i], FALSE);
44: if (!data)
45: {
46: fprintf(stderr, "opening %s failed: %s\n", argv[i], strerror(errno));
47: return 1;
48: }
49: res = LLVMFuzzerTestOneInput(data->ptr, data->len);
50: fprintf(stderr, "done: %s: (%zd bytes)\n", argv[i], data->len);
51: chunk_unmap(data);
52: if (res)
53: {
54: break;
55: }
56: }
57: fprintf(stderr, "%s: completed %d inputs\n", argv[0], i-1);
58: return res;
59: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>