suricata
onefile.c
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include "autoconf.h"
5 
6 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
7 
8 int main(int argc, char** argv)
9 {
10  FILE * fp;
11  uint8_t *data;
12  size_t size;
13 
14  if (argc != 2) {
15  return 1;
16  }
17 #ifdef AFLFUZZ_PERSISTANT_MODE
18  while (__AFL_LOOP(1000)) {
19 #endif /* AFLFUZZ_PERSISTANT_MODE */
20 
21  //opens the file, get its size, and reads it into a buffer
22  fp = fopen(argv[1], "rb");
23  if (fp == NULL) {
24  return 2;
25  }
26  if (fseek(fp, 0L, SEEK_END) != 0) {
27  fclose(fp);
28  return 2;
29  }
30  size = ftell(fp);
31  if (size == (size_t) -1) {
32  fclose(fp);
33  return 2;
34  }
35  if (fseek(fp, 0L, SEEK_SET) != 0) {
36  fclose(fp);
37  return 2;
38  }
39  data = malloc(size);
40  if (data == NULL) {
41  fclose(fp);
42  return 2;
43  }
44  if (fread(data, size, 1, fp) != 1) {
45  fclose(fp);
46  free(data);
47  return 2;
48  }
49 
50  //lauch fuzzer
51  LLVMFuzzerTestOneInput(data, size);
52  free(data);
53  fclose(fp);
54 #ifdef AFLFUZZ_PERSISTANT_MODE
55  }
56 #endif /* AFLFUZZ_PERSISTANT_MODE */
57 
58  return 0;
59 }
60 
main
int main(int argc, char **argv)
Definition: onefile.c:8
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition: fuzz_applayerparserparse.c:35