2 * General driver to allow command-line fuzzer (i.e. afl) to
3 * exercise the libFuzzer entrypoint.
17 #define kMaxAflInputSize (1 << 20)
18 static unsigned char afl_buffer[kMaxAflInputSize];
21 /* If we are built with afl-clang-fast, use persistent mode */
22 #define KEEP_FUZZING(count) __AFL_LOOP(1000)
24 /* If we are built with afl-clang, execute each input once */
25 #define KEEP_FUZZING(count) ((count) < 1)
28 /* In ares-test-fuzz.c and ares-test-fuzz-name.c: */
29 int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size);
31 static void ProcessFile(int fd) {
32 int count = read(fd, afl_buffer, kMaxAflInputSize);
34 * Make a copy of the data so that it's not part of a larger
35 * buffer (where buffer overflows would go unnoticed).
37 unsigned char *copied_data = (unsigned char *)malloc(count);
38 memcpy(copied_data, afl_buffer, count);
39 LLVMFuzzerTestOneInput(copied_data, count);
43 int main(int argc, char *argv[]) {
46 while (KEEP_FUZZING(count)) {
47 ProcessFile(fileno(stdin));
52 for (ii = 1; ii < argc; ++ii) {
53 int fd = open(argv[ii], O_RDONLY);
55 fprintf(stderr, "Failed to open '%s'\n", argv[ii]);