1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 /* This file doesn't use any Mbed TLS function, but grab mbedtls_config.h anyway
6 * in case it contains platform-specific #defines related to malloc or
7 * stdio functions. */
8 #include "mbedtls/build_info.h"
9
10 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
11
main(int argc,char ** argv)12 int main(int argc, char **argv)
13 {
14 FILE *fp;
15 uint8_t *Data;
16 size_t Size;
17
18 if (argc != 2) {
19 return 1;
20 }
21 //opens the file, get its size, and reads it into a buffer
22 fp = fopen(argv[1], "rb");
23 if (fp == NULL) {
24 return 2;
25 }
26 if (fseek(fp, 0L, SEEK_END) != 0) {
27 fclose(fp);
28 return 2;
29 }
30 Size = ftell(fp);
31 if (Size == (size_t) -1) {
32 fclose(fp);
33 return 2;
34 }
35 if (fseek(fp, 0L, SEEK_SET) != 0) {
36 fclose(fp);
37 return 2;
38 }
39 Data = malloc(Size);
40 if (Data == NULL) {
41 fclose(fp);
42 return 2;
43 }
44 if (fread(Data, Size, 1, fp) != 1) {
45 free(Data);
46 fclose(fp);
47 return 2;
48 }
49
50 //launch fuzzer
51 LLVMFuzzerTestOneInput(Data, Size);
52 free(Data);
53 fclose(fp);
54 return 0;
55 }
56