test: make fuzzer driver code C not C++

pull/62/head
David Drysdale 9 years ago
parent 5a1ae0bc7a
commit edc76de17e
  1. 4
      test/Makefile.inc
  2. 10
      test/ares-fuzz.c
  3. 3
      test/ares-test-fuzz.c

@ -22,8 +22,8 @@ TESTSOURCES = ares-test-main.cc \
TESTHEADERS = ares-test.h \ TESTHEADERS = ares-test.h \
dns-proto.h dns-proto.h
FUZZSOURCES = ares-test-fuzz.cc \ FUZZSOURCES = ares-test-fuzz.c \
ares-fuzz.cc ares-fuzz.c
DUMPSOURCES = dns-proto.cc \ DUMPSOURCES = dns-proto.cc \
dns-dump.cc dns-dump.cc

@ -10,7 +10,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
static const int kMaxAflInputSize = 1 << 20; #define kMaxAflInputSize (1 << 20)
static unsigned char afl_buffer[kMaxAflInputSize]; static unsigned char afl_buffer[kMaxAflInputSize];
#ifdef __AFL_LOOP #ifdef __AFL_LOOP
@ -21,9 +21,8 @@ static unsigned char afl_buffer[kMaxAflInputSize];
#define KEEP_FUZZING(count) ((count) < 1) #define KEEP_FUZZING(count) ((count) < 1)
#endif #endif
/* In ares-test-fuzz.cc: */ /* In ares-test-fuzz.c: */
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size);
unsigned long size);
static void ProcessFile(int fd) { static void ProcessFile(int fd) {
ssize_t count = read(fd, afl_buffer, kMaxAflInputSize); ssize_t count = read(fd, afl_buffer, kMaxAflInputSize);
@ -44,7 +43,8 @@ int main(int argc, char *argv[]) {
count++; count++;
} }
} else { } else {
for (int ii = 1; ii < argc; ++ii) { int ii;
for (ii = 1; ii < argc; ++ii) {
int fd = open(argv[ii], O_RDONLY); int fd = open(argv[ii], O_RDONLY);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "Failed to open '%s'\n", argv[ii]); fprintf(stderr, "Failed to open '%s'\n", argv[ii]);

@ -3,9 +3,6 @@
#include "ares.h" #include "ares.h"
// Entrypoint for Clang's libfuzzer // Entrypoint for Clang's libfuzzer
#ifdef __cplusplus
extern "C"
#endif
int LLVMFuzzerTestOneInput(const unsigned char *data, int LLVMFuzzerTestOneInput(const unsigned char *data,
unsigned long size) { unsigned long size) {
// Feed the data into each of the ares_parse_*_reply functions. // Feed the data into each of the ares_parse_*_reply functions.
Loading…
Cancel
Save