Debian Codegraph @

tests/fuzz/fuzzer.c

raw
1 /* Simpler gnu89 version of StandaloneFuzzTargetMain.c from LLVM */
2
3 #include "config.h"
4
5 #include <assert.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI)
9 /* for OPENSSL_cleanup() of GSSAPI's OpenSSL context */
10 #include <openssl/crypto.h>
11 #endif
12
13 int LLVMFuzzerTestOneInput (const unsigned char *data, size_t size);
14 __attribute__((weak)) int LLVMFuzzerInitialize(int *argc, char ***argv);
15
16 int
17 main (int argc, char **argv)
18 {
19 FILE *f = NULL;
20 size_t n_read, len;
21 unsigned char *buf = NULL;
22
23 if (argc < 2) {
24 return 1;
25 }
26
27 if (LLVMFuzzerInitialize) {
28 LLVMFuzzerInitialize(&argc, &argv);
29 }
30
31 f = fopen (argv[1], "r");
32 assert (f);
33 fseek (f, 0, SEEK_END);
34 len = ftell (f);
35 fseek (f, 0, SEEK_SET);
36 buf = (unsigned char*) malloc (len);
37 n_read = fread (buf, 1, len, f);
38 fclose (f);
39 assert (n_read == len);
40 LLVMFuzzerTestOneInput (buf, len);
41
42 free (buf);
43 printf ("Done!\n");
44
45 #if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI)
46 OPENSSL_cleanup();
47 #endif
48 return 0;
49 }