Merge branch 'master' of https://github.com/bvanassche/fio
[fio.git] / t / fuzz / onefile.c
CommitLineData
1857e6b2
PA
1#include <stdint.h>
2#include <stdlib.h>
3#include <stdio.h>
4
5int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
6
7int main(int argc, char** argv)
8{
9 FILE *fp;
10 uint8_t *data;
11 size_t size;
12
13 if (argc != 2)
14 return 1;
15
16 /* opens the file, get its size, and reads it into a buffer */
17 fp = fopen(argv[1], "rb");
18 if (fp == NULL)
19 return 2;
20
21 if (fseek(fp, 0L, SEEK_END) != 0) {
22 fclose(fp);
23 return 2;
24 }
25 size = ftell(fp);
26 if (size == (size_t) -1) {
27 fclose(fp);
28 return 2;
29 }
30 if (fseek(fp, 0L, SEEK_SET) != 0) {
31 fclose(fp);
32 return 2;
33 }
34 data = malloc(size);
35 if (data == NULL) {
36 fclose(fp);
37 return 2;
38 }
39 if (fread(data, size, 1, fp) != 1) {
40 fclose(fp);
41 free(data);
42 return 2;
43 }
44
45 /* launch fuzzer */
46 LLVMFuzzerTestOneInput(data, size);
47 free(data);
48 fclose(fp);
49
50 return 0;
51}