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