1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
6
main(int argc,char ** argv)7 int main(int argc, char **argv) {
8 int i;
9 fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1);
10
11 for (i = 1; i < argc; i++) {
12 size_t len, n_read, err;
13 unsigned char *buf;
14 FILE *f = fopen(argv[i], "rb+");
15 if (!f) {
16 /* Failed to open this file: it may be a directory. */
17 fprintf(stderr, "Skipping: %s\n", argv[i]);
18 continue;
19 }
20 fprintf(stderr, "Running: %s %s\n", argv[0], argv[i]);
21 fseek(f, 0, SEEK_END);
22 len = ftell(f);
23 fseek(f, 0, SEEK_SET);
24 buf = (unsigned char *)malloc(len);
25 n_read = fread(buf, 1, len, f);
26 assert(n_read == len);
27 LLVMFuzzerTestOneInput(buf, len);
28 free(buf);
29 err = fclose(f);
30 assert(err == 0);
31 (void)err;
32 fprintf(stderr, "Done: %s: (%d bytes)\n", argv[i], (int)n_read);
33 }
34
35 return 0;
36 }
37