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
|
// General driver to allow command-line fuzzer (i.e. afl) to
|
||||||
// fuzz the libfuzzer entrypoint.
|
// fuzz the libfuzzer entrypoint.
|
||||||
|
#include <sys/types.h> |
||||||
|
#include <fcntl.h> |
||||||
#include <stdio.h> |
#include <stdio.h> |
||||||
#include <unistd.h> |
#include <unistd.h> |
||||||
|
|
||||||
|
#include <iostream> |
||||||
|
|
||||||
#include <vector> |
#include <vector> |
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, |
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, |
||||||
unsigned long size); |
unsigned long size); |
||||||
int main() { |
|
||||||
|
static void ProcessFile(int fd) { |
||||||
std::vector<unsigned char> input; |
std::vector<unsigned char> input; |
||||||
while (true) { |
while (true) { |
||||||
unsigned char buffer[1024]; |
unsigned char buffer[1024]; |
||||||
int len = read(fileno(stdin), buffer, sizeof(buffer)); |
int len = read(fd, buffer, sizeof(buffer)); |
||||||
if (len <= 0) break; |
if (len <= 0) break; |
||||||
input.insert(input.end(), buffer, buffer + len); |
input.insert(input.end(), buffer, buffer + len); |
||||||
} |
} |
||||||
LLVMFuzzerTestOneInput(input.data(), input.size()); |
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; |
return 0; |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue