2018-05-03 16:40:24 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2019-08-13 18:00:02 +02:00
|
|
|
|
2021-05-28 09:42:25 +02:00
|
|
|
/* This file doesn't use any Mbed TLS function, but grab mbedtls_config.h anyway
|
2019-08-13 18:00:02 +02:00
|
|
|
* in case it contains platform-specific #defines related to malloc or
|
|
|
|
* stdio functions. */
|
2021-05-27 11:25:03 +02:00
|
|
|
#include "mbedtls/build_info.h"
|
2018-05-03 16:40:24 +02:00
|
|
|
|
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
int main(int argc, char **argv)
|
2018-05-03 16:40:24 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
FILE *fp;
|
2018-05-03 16:40:24 +02:00
|
|
|
uint8_t *Data;
|
|
|
|
size_t Size;
|
2023-05-12 13:18:08 +02:00
|
|
|
const char *argv0 = argv[0] == NULL ? "PROGRAM_NAME" : argv[0];
|
2018-05-03 16:40:24 +02:00
|
|
|
|
|
|
|
if (argc != 2) {
|
2023-05-12 13:18:08 +02:00
|
|
|
fprintf(stderr, "Usage: %s REPRODUCER_FILE\n", argv0);
|
2018-05-03 16:40:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
//opens the file, get its size, and reads it into a buffer
|
|
|
|
fp = fopen(argv[1], "rb");
|
|
|
|
if (fp == NULL) {
|
2023-05-12 13:18:08 +02:00
|
|
|
fprintf(stderr, "%s: Error in fopen\n", argv0);
|
|
|
|
perror(argv[1]);
|
2018-05-03 16:40:24 +02:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (fseek(fp, 0L, SEEK_END) != 0) {
|
2023-05-12 13:18:08 +02:00
|
|
|
fprintf(stderr, "%s: Error in fseek(SEEK_END)\n", argv0);
|
|
|
|
perror(argv[1]);
|
2018-05-03 16:40:24 +02:00
|
|
|
fclose(fp);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
Size = ftell(fp);
|
|
|
|
if (Size == (size_t) -1) {
|
2023-05-12 13:18:08 +02:00
|
|
|
fprintf(stderr, "%s: Error in ftell\n", argv0);
|
|
|
|
perror(argv[1]);
|
2018-05-03 16:40:24 +02:00
|
|
|
fclose(fp);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (fseek(fp, 0L, SEEK_SET) != 0) {
|
2023-05-12 13:18:08 +02:00
|
|
|
fprintf(stderr, "%s: Error in fseek(0)\n", argv0);
|
|
|
|
perror(argv[1]);
|
2018-05-03 16:40:24 +02:00
|
|
|
fclose(fp);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
Data = malloc(Size);
|
|
|
|
if (Data == NULL) {
|
2023-05-12 13:18:08 +02:00
|
|
|
fprintf(stderr, "%s: Could not allocate memory\n", argv0);
|
|
|
|
perror(argv[1]);
|
2018-05-03 16:40:24 +02:00
|
|
|
fclose(fp);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (fread(Data, Size, 1, fp) != 1) {
|
2023-05-12 13:18:08 +02:00
|
|
|
fprintf(stderr, "%s: Error in fread\n", argv0);
|
|
|
|
perror(argv[1]);
|
2019-06-04 12:06:34 +02:00
|
|
|
free(Data);
|
2018-05-03 16:40:24 +02:00
|
|
|
fclose(fp);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2021-12-21 06:14:10 +01:00
|
|
|
//launch fuzzer
|
2018-05-03 16:40:24 +02:00
|
|
|
LLVMFuzzerTestOneInput(Data, Size);
|
2019-06-04 12:06:34 +02:00
|
|
|
free(Data);
|
2018-05-03 16:40:24 +02:00
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|