blob: 9e3986d6b7ee4aac651aff469cfd5d223b9d84bc [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>
Philippe Antoine42a2ce82019-07-10 14:26:31 +02004// Get platform-specific definition
5#include "mbedtls/config.h"
Philippe Antoine72333522018-05-03 16:40:24 +02006
7int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
8
9int main(int argc, char** argv)
10{
11 FILE * fp;
12 uint8_t *Data;
13 size_t Size;
14
15 if (argc != 2) {
16 return 1;
17 }
18 //opens the file, get its size, and reads it into a buffer
19 fp = fopen(argv[1], "rb");
20 if (fp == NULL) {
21 return 2;
22 }
23 if (fseek(fp, 0L, SEEK_END) != 0) {
24 fclose(fp);
25 return 2;
26 }
27 Size = ftell(fp);
28 if (Size == (size_t) -1) {
29 fclose(fp);
30 return 2;
31 }
32 if (fseek(fp, 0L, SEEK_SET) != 0) {
33 fclose(fp);
34 return 2;
35 }
36 Data = malloc(Size);
37 if (Data == NULL) {
38 fclose(fp);
39 return 2;
40 }
41 if (fread(Data, Size, 1, fp) != 1) {
Philippe Antoine3abe15b2019-06-04 12:06:34 +020042 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020043 fclose(fp);
44 return 2;
45 }
46
47 //lauch fuzzer
48 LLVMFuzzerTestOneInput(Data, Size);
Philippe Antoine3abe15b2019-06-04 12:06:34 +020049 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020050 fclose(fp);
51 return 0;
52}
53