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