Debian Codegraph @

suite/fuzz/driverbin.c

raw symbols SCIP
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <dirent.h>
5 #include <unistd.h>
6
7 #include "platform.h"
8
9 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
10
11 int main(int argc, char** argv)
12 {
13 FILE * fp;
14 uint8_t Data[0x1000];
15 size_t Size;
16 DIR *d;
17 struct dirent *dir;
18 int r = 0;
19 int i;
20
21 if (argc != 2) {
22 return 1;
23 }
24
25 d = opendir(argv[1]);
26 if (d == NULL) {
27 printf("Invalid directory\n");
28 return 2;
29 }
30 if (chdir(argv[1]) != 0) {
31 closedir(d);
32 printf("Invalid directory\n");
33 return 2;
34 }
35
36 while((dir = readdir(d)) != NULL) {
37 //opens the file, get its size, and reads it into a buffer
38 if (dir->d_type != DT_REG) {
39 continue;
40 }
41 printf("Running file %s ", dir->d_name);
42 fflush(stdout);
43 fp = fopen(dir->d_name, "rb");
44 if (fp == NULL) {
45 r = 3;
46 break;
47 }
48 if (fseek(fp, 0L, SEEK_END) != 0) {
49 fclose(fp);
50 r = 4;
51 break;
52 }
53 Size = ftell(fp);
54 if (Size == (size_t) -1) {
55 fclose(fp);
56 r = 5;
57 break;
58 } else if (Size > 0x1000) {
59 fclose(fp);
60 continue;
61 }
62 if (fseek(fp, 0L, SEEK_SET) != 0) {
63 fclose(fp);
64 r = 7;
65 break;
66 }
67 if (fread(Data, Size, 1, fp) != 1) {
68 fclose(fp);
69 r = 8;
70 break;
71 }
72 if (Size > 0) {
73 printf("command cstool %s\n", get_platform_cstoolname(Data[0]));
74 }
75 for (i=0; i<Size; i++) {
76 printf("%02x", Data[i]);
77 }
78 printf("\n");
79
80 //lauch fuzzer
81 LLVMFuzzerTestOneInput(Data, Size);
82 fclose(fp);
83 }
84 closedir(d);
85 printf("Ok : whole directory finished\n");
86 return r;
87 }
88