blob: 45c32829f65a2e412527321f6ccc189ba82c4c7d [file] [log] [blame]
Philippe Antoine72333522018-05-03 16:40:24 +02001#include <stdint.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <stdio.h>
5
6int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
7
8int main(int argc, char** argv)
9{
10 FILE * fp;
11 uint8_t *Data;
12 size_t Size;
13
14 if (argc != 2) {
15 return 1;
16 }
17 //opens the file, get its size, and reads it into a buffer
18 fp = fopen(argv[1], "rb");
19 if (fp == NULL) {
20 return 2;
21 }
22 if (fseek(fp, 0L, SEEK_END) != 0) {
23 fclose(fp);
24 return 2;
25 }
26 Size = ftell(fp);
27 if (Size == (size_t) -1) {
28 fclose(fp);
29 return 2;
30 }
31 if (fseek(fp, 0L, SEEK_SET) != 0) {
32 fclose(fp);
33 return 2;
34 }
35 Data = malloc(Size);
36 if (Data == NULL) {
37 fclose(fp);
38 return 2;
39 }
40 if (fread(Data, Size, 1, fp) != 1) {
Philippe Antoine3abe15b2019-06-04 12:06:34 +020041 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020042 fclose(fp);
43 return 2;
44 }
45
46 //lauch fuzzer
47 LLVMFuzzerTestOneInput(Data, Size);
Philippe Antoine3abe15b2019-06-04 12:06:34 +020048 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020049 fclose(fp);
50 return 0;
51}
52