blob: 8399735075bd2a966988daa885c224906268fa61 [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
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)
Philippe Antoine42a2ce82019-07-10 14:26:31 +02009#include "mbedtls/config.h"
Gilles Peskine26f3e282019-08-13 18:00:02 +020010#else
11#include MBEDTLS_CONFIG_FILE
12#endif
Philippe Antoine72333522018-05-03 16:40:24 +020013
14int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
15
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010016int main(int argc, char **argv)
Philippe Antoine72333522018-05-03 16:40:24 +020017{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010018 FILE *fp;
Philippe Antoine72333522018-05-03 16:40:24 +020019 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) {
Philippe Antoine3abe15b2019-06-04 12:06:34 +020049 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020050 fclose(fp);
51 return 2;
52 }
53
Shaun Case0e7791f2021-12-20 21:14:10 -080054 //launch fuzzer
Philippe Antoine72333522018-05-03 16:40:24 +020055 LLVMFuzzerTestOneInput(Data, Size);
Philippe Antoine3abe15b2019-06-04 12:06:34 +020056 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020057 fclose(fp);
58 return 0;
59}