]> wimlib.net Git - wimlib/blob - tools/libFuzzer/test-one-input.c
mount_image.c: add fallback definitions of RENAME_* constants
[wimlib] / tools / libFuzzer / test-one-input.c
1 #include <fcntl.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <sys/stat.h>
6 #include <unistd.h>
7
8 int LLVMFuzzerTestOneInput(const uint8_t *in, size_t insize);
9
10 int main(int argc, char *argv[])
11 {
12         int fd;
13         struct stat stbuf;
14         uint8_t *in;
15
16         fd = open(argv[1], O_RDONLY);
17         if (fd < 0) {
18                 perror(argv[1]);
19                 return 1;
20         }
21         if (fstat(fd, &stbuf) != 0) {
22                 perror("fstat");
23                 return 1;
24         }
25         in = malloc(stbuf.st_size);
26         if (read(fd, in, stbuf.st_size) != stbuf.st_size) {
27                 perror("read");
28                 return 1;
29         }
30         LLVMFuzzerTestOneInput(in, stbuf.st_size);
31         close(fd);
32         free(in);
33         return 0;
34 }