driverbin.c
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <dirent.h>
5 #include <unistd.h>
6 
7 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
8 
9 int main(int argc, char** argv)
10 {
11  FILE * fp;
12  uint8_t Data[0x1000];
13  size_t Size;
14  DIR *d;
15  struct dirent *dir;
16  int r = 0;
17 
18  if (argc != 2) {
19  return 1;
20  }
21 
22  d = opendir(argv[1]);
23  if (d == NULL) {
24  printf("Invalid directory\n");
25  return 2;
26  }
27  if (chdir(argv[1]) != 0) {
28  closedir(d);
29  printf("Invalid directory\n");
30  return 2;
31  }
32 
33  while((dir = readdir(d)) != NULL) {
34  //opens the file, get its size, and reads it into a buffer
35  if (dir->d_type != DT_REG) {
36  continue;
37  }
38  //printf("Running %s\n", dir->d_name);
39  fp = fopen(dir->d_name, "rb");
40  if (fp == NULL) {
41  r = 3;
42  break;
43  }
44  if (fseek(fp, 0L, SEEK_END) != 0) {
45  fclose(fp);
46  r = 4;
47  break;
48  }
49  Size = ftell(fp);
50  if (Size == (size_t) -1) {
51  fclose(fp);
52  r = 5;
53  break;
54  } else if (Size > 0x1000) {
55  fclose(fp);
56  continue;
57  }
58  if (fseek(fp, 0L, SEEK_SET) != 0) {
59  fclose(fp);
60  r = 7;
61  break;
62  }
63  if (fread(Data, Size, 1, fp) != 1) {
64  fclose(fp);
65  r = 8;
66  break;
67  }
68 
69  //lauch fuzzer
70  LLVMFuzzerTestOneInput(Data, Size);
71  fclose(fp);
72  }
73  closedir(d);
74  return r;
75 }
76 
main
int main(int argc, char **argv)
Definition: driverbin.c:9
SEEK_END
#define SEEK_END
Definition: bloaty/third_party/zlib/contrib/minizip/zip.c:84
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
d
static const fe d
Definition: curve25519_tables.h:19
stdint.h
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition: sockaddr_utils_fuzzer_test.cc:29
benchmark.FILE
FILE
Definition: benchmark.py:21
grpc::fclose
fclose(creds_file)
L
lua_State * L
Definition: upb/upb/bindings/lua/main.c:35
fix_build_deps.r
r
Definition: fix_build_deps.py:491
SEEK_SET
#define SEEK_SET
Definition: bloaty/third_party/zlib/contrib/minizip/zip.c:88


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:13