• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 config.h anyway
6  * in case it contains platform-specific #defines related to malloc or
7  * stdio functions. */
8 #if !defined(MBEDTLS_CONFIG_FILE)
9 #include "mbedtls/config.h"
10 #else
11 #include MBEDTLS_CONFIG_FILE
12 #endif
13 
14 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
15 
main(int argc,char ** argv)16 int main(int argc, char** argv)
17 {
18     FILE * fp;
19     uint8_t *Data;
20     size_t Size;
21 
22     if (argc != 2) {
23         return 1;
24     }
25     //opens the file, get its size, and reads it into a buffer
26     fp = fopen(argv[1], "rb");
27     if (fp == NULL) {
28         return 2;
29     }
30     if (fseek(fp, 0L, SEEK_END) != 0) {
31         fclose(fp);
32         return 2;
33     }
34     Size = ftell(fp);
35     if (Size == (size_t) -1) {
36         fclose(fp);
37         return 2;
38     }
39     if (fseek(fp, 0L, SEEK_SET) != 0) {
40         fclose(fp);
41         return 2;
42     }
43     Data = malloc(Size);
44     if (Data == NULL) {
45         fclose(fp);
46         return 2;
47     }
48     if (fread(Data, Size, 1, fp) != 1) {
49         free(Data);
50         fclose(fp);
51         return 2;
52     }
53 
54     //lauch fuzzer
55     LLVMFuzzerTestOneInput(Data, Size);
56     free(Data);
57     fclose(fp);
58     return 0;
59 }
60 
61