diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
commit | be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch) | |
tree | 9754ff1ca740f6346cf8483ec915d4054bc5da2d /fluent-bit/lib/c-ares-1.19.1/test/ares-fuzz.c | |
parent | Initial commit. (diff) | |
download | netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip |
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/lib/c-ares-1.19.1/test/ares-fuzz.c')
-rw-r--r-- | fluent-bit/lib/c-ares-1.19.1/test/ares-fuzz.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/fluent-bit/lib/c-ares-1.19.1/test/ares-fuzz.c b/fluent-bit/lib/c-ares-1.19.1/test/ares-fuzz.c new file mode 100644 index 00000000..5526f462 --- /dev/null +++ b/fluent-bit/lib/c-ares-1.19.1/test/ares-fuzz.c @@ -0,0 +1,63 @@ +/* + * General driver to allow command-line fuzzer (i.e. afl) to + * exercise the libFuzzer entrypoint. + */ + +#include <sys/types.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#ifdef WIN32 +#include <io.h> +#else +#include <unistd.h> +#endif + +#define kMaxAflInputSize (1 << 20) +static unsigned char afl_buffer[kMaxAflInputSize]; + +#ifdef __AFL_LOOP +/* If we are built with afl-clang-fast, use persistent mode */ +#define KEEP_FUZZING(count) __AFL_LOOP(1000) +#else +/* If we are built with afl-clang, execute each input once */ +#define KEEP_FUZZING(count) ((count) < 1) +#endif + +/* In ares-test-fuzz.c and ares-test-fuzz-name.c: */ +int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size); + +static void ProcessFile(int fd) { + int count = read(fd, afl_buffer, kMaxAflInputSize); + /* + * Make a copy of the data so that it's not part of a larger + * buffer (where buffer overflows would go unnoticed). + */ + unsigned char *copied_data = (unsigned char *)malloc(count); + memcpy(copied_data, afl_buffer, count); + LLVMFuzzerTestOneInput(copied_data, count); + free(copied_data); +} + +int main(int argc, char *argv[]) { + if (argc == 1) { + int count = 0; + while (KEEP_FUZZING(count)) { + ProcessFile(fileno(stdin)); + count++; + } + } else { + int ii; + for (ii = 1; ii < argc; ++ii) { + int fd = open(argv[ii], O_RDONLY); + if (fd < 0) { + fprintf(stderr, "Failed to open '%s'\n", argv[ii]); + continue; + } + ProcessFile(fd); + close(fd); + } + } + return 0; +} |