blob: 6c02a641dabc23dbeafd9d76859702d28aac6565 [file] [log] [blame]
Felix Conway998760a2025-03-24 11:37:33 +00001#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
2
Philippe Antoine72333522018-05-03 16:40:24 +02003#include <stdint.h>
Philippe Antoine72333522018-05-03 16:40:24 +02004#include <stdlib.h>
5#include <stdio.h>
Michael Schustere708e862024-06-01 21:08:45 +02006#include "common.h"
Gilles Peskine26f3e282019-08-13 18:00:02 +02007
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +02008/* This file doesn't use any Mbed TLS function, but grab mbedtls_config.h anyway
Gilles Peskine26f3e282019-08-13 18:00:02 +02009 * in case it contains platform-specific #defines related to malloc or
10 * stdio functions. */
Bence Szépkútic662b362021-05-27 11:25:03 +020011#include "mbedtls/build_info.h"
Philippe Antoine72333522018-05-03 16:40:24 +020012
Gilles Peskine449bd832023-01-11 14:50:10 +010013int main(int argc, char **argv)
Philippe Antoine72333522018-05-03 16:40:24 +020014{
Gilles Peskine449bd832023-01-11 14:50:10 +010015 FILE *fp;
Philippe Antoine72333522018-05-03 16:40:24 +020016 uint8_t *Data;
17 size_t Size;
Gilles Peskine1f9d8a42023-05-12 13:18:08 +020018 const char *argv0 = argv[0] == NULL ? "PROGRAM_NAME" : argv[0];
Philippe Antoine72333522018-05-03 16:40:24 +020019
20 if (argc != 2) {
Gilles Peskine1f9d8a42023-05-12 13:18:08 +020021 fprintf(stderr, "Usage: %s REPRODUCER_FILE\n", argv0);
Philippe Antoine72333522018-05-03 16:40:24 +020022 return 1;
23 }
24 //opens the file, get its size, and reads it into a buffer
25 fp = fopen(argv[1], "rb");
26 if (fp == NULL) {
Gilles Peskine1f9d8a42023-05-12 13:18:08 +020027 fprintf(stderr, "%s: Error in fopen\n", argv0);
28 perror(argv[1]);
Philippe Antoine72333522018-05-03 16:40:24 +020029 return 2;
30 }
31 if (fseek(fp, 0L, SEEK_END) != 0) {
Gilles Peskine1f9d8a42023-05-12 13:18:08 +020032 fprintf(stderr, "%s: Error in fseek(SEEK_END)\n", argv0);
33 perror(argv[1]);
Philippe Antoine72333522018-05-03 16:40:24 +020034 fclose(fp);
35 return 2;
36 }
37 Size = ftell(fp);
38 if (Size == (size_t) -1) {
Gilles Peskine1f9d8a42023-05-12 13:18:08 +020039 fprintf(stderr, "%s: Error in ftell\n", argv0);
40 perror(argv[1]);
Philippe Antoine72333522018-05-03 16:40:24 +020041 fclose(fp);
42 return 2;
43 }
44 if (fseek(fp, 0L, SEEK_SET) != 0) {
Gilles Peskine1f9d8a42023-05-12 13:18:08 +020045 fprintf(stderr, "%s: Error in fseek(0)\n", argv0);
46 perror(argv[1]);
Philippe Antoine72333522018-05-03 16:40:24 +020047 fclose(fp);
48 return 2;
49 }
50 Data = malloc(Size);
51 if (Data == NULL) {
Gilles Peskine1f9d8a42023-05-12 13:18:08 +020052 fprintf(stderr, "%s: Could not allocate memory\n", argv0);
53 perror(argv[1]);
Philippe Antoine72333522018-05-03 16:40:24 +020054 fclose(fp);
55 return 2;
56 }
57 if (fread(Data, Size, 1, fp) != 1) {
Gilles Peskine1f9d8a42023-05-12 13:18:08 +020058 fprintf(stderr, "%s: Error in fread\n", argv0);
59 perror(argv[1]);
Philippe Antoine3abe15b2019-06-04 12:06:34 +020060 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020061 fclose(fp);
62 return 2;
63 }
64
Shaun Case8b0ecbc2021-12-20 21:14:10 -080065 //launch fuzzer
Philippe Antoine72333522018-05-03 16:40:24 +020066 LLVMFuzzerTestOneInput(Data, Size);
Philippe Antoine3abe15b2019-06-04 12:06:34 +020067 free(Data);
Philippe Antoine72333522018-05-03 16:40:24 +020068 fclose(fp);
69 return 0;
70}