blob: efd8dbb8283c1c57f4c7c308c12e0c8dd72e24fc [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>
Gilles Peskine26f3e282019-08-13 18:00:02 +02004
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +02005/* This file doesn't use any Mbed TLS function, but grab mbedtls_config.h anyway
Gilles Peskine26f3e282019-08-13 18:00:02 +02006 * in case it contains platform-specific #defines related to malloc or
7 * stdio functions. */
Bence Szépkútic662b362021-05-27 11:25:03 +02008#include "mbedtls/build_info.h"
Philippe Antoine72333522018-05-03 16:40:24 +02009
10int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
11
12int 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) {
Philippe Antoine3abe15b2019-06-04 12:06:34 +020045 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020046 fclose(fp);
47 return 2;
48 }
49
50 //lauch fuzzer
51 LLVMFuzzerTestOneInput(Data, Size);
Philippe Antoine3abe15b2019-06-04 12:06:34 +020052 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020053 fclose(fp);
54 return 0;
55}
56