mirror of https://github.com/c-ares/c-ares.git
If no arguments are specified, use stdin as input. Otherwise treat each argument as a filename and feed its contents to the fuzz entrypoint.pull/54/head
parent
d52df9123f
commit
cc6a16d6c2
1 changed files with 23 additions and 2 deletions
@ -1,20 +1,41 @@ |
||||
// General driver to allow command-line fuzzer (i.e. afl) to
|
||||
// fuzz the libfuzzer entrypoint.
|
||||
#include <sys/types.h> |
||||
#include <fcntl.h> |
||||
#include <stdio.h> |
||||
#include <unistd.h> |
||||
|
||||
#include <iostream> |
||||
|
||||
#include <vector> |
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, |
||||
unsigned long size); |
||||
int main() { |
||||
|
||||
static void ProcessFile(int fd) { |
||||
std::vector<unsigned char> input; |
||||
while (true) { |
||||
unsigned char buffer[1024]; |
||||
int len = read(fileno(stdin), buffer, sizeof(buffer)); |
||||
int len = read(fd, buffer, sizeof(buffer)); |
||||
if (len <= 0) break; |
||||
input.insert(input.end(), buffer, buffer + len); |
||||
} |
||||
LLVMFuzzerTestOneInput(input.data(), input.size()); |
||||
} |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
if (argc == 1) { |
||||
ProcessFile(fileno(stdin)); |
||||
} else { |
||||
for (int ii = 1; ii < argc; ++ii) { |
||||
int fd = open(argv[ii], O_RDONLY); |
||||
if (fd < 0) { |
||||
std::cerr << "Failed to open '" << argv[ii] << "'" << std::endl; |
||||
continue; |
||||
} |
||||
ProcessFile(fd); |
||||
close(fd); |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
Loading…
Reference in new issue