summaryrefslogtreecommitdiff
path: root/fuzzers/standalone_driver.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-07-19 13:29:46 +0200
committerPatrick Steinhardt <ps@pks.im>2018-08-03 09:50:35 +0200
commit59328ed84e3a83dd41e4f319f0b985bd7a9a40a3 (patch)
tree09568d380d8fdca7a6b406047a49922942ca003c /fuzzers/standalone_driver.c
parent60e610a23628a51484a1abd3c2295600ef3d1b7c (diff)
downloadlibgit2-59328ed84e3a83dd41e4f319f0b985bd7a9a40a3.tar.gz
fuzzers: rename "fuzz" directory to match our style
Our layout uses names like "examples" or "tests" which is why the "fuzz" directory doesn't really fit in here. Rename the directory to be called "fuzzers" instead. Furthermore, we rename the fuzzer "fuzz_packfile_raw" to "packfile_raw_fuzzer", which is also in line with the already existing fuzzer at google/oss-fuzz. While at it, rename the "packfile_raw" fuzzer to instead just be called "packfile" fuzzer.
Diffstat (limited to 'fuzzers/standalone_driver.c')
-rw-r--r--fuzzers/standalone_driver.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/fuzzers/standalone_driver.c b/fuzzers/standalone_driver.c
new file mode 100644
index 000000000..fd8453d8b
--- /dev/null
+++ b/fuzzers/standalone_driver.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include <assert.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+#include "fileops.h"
+#include "path.h"
+
+extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
+extern int LLVMFuzzerInitialize(int *argc, char ***argv);
+
+static int run_one_file(const char *filename)
+{
+ git_buf buf = GIT_BUF_INIT;
+ int error = 0;
+
+ if (git_futils_readbuffer(&buf, filename) < 0) {
+ fprintf(stderr, "Failed to read %s: %m\n", filename);
+ error = -1;
+ goto exit;
+ }
+
+ LLVMFuzzerTestOneInput((const unsigned char *)buf.ptr, buf.size);
+exit:
+ git_buf_dispose(&buf);
+ return error;
+}
+
+int main(int argc, char **argv)
+{
+ git_vector corpus_files = GIT_VECTOR_INIT;
+ char *filename = NULL;
+ unsigned i = 0;
+ int error = 0;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <corpus directory>\n", argv[0]);
+ error = -1;
+ goto exit;
+ }
+
+ fprintf(stderr, "Running %s against %s\n", argv[0], argv[1]);
+ LLVMFuzzerInitialize(&argc, &argv);
+
+ if (git_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) {
+ fprintf(stderr, "Failed to scan corpus directory: %m\n");
+ error = -1;
+ goto exit;
+ }
+ git_vector_foreach(&corpus_files, i, filename) {
+ fprintf(stderr, "\tRunning %s...\n", filename);
+ if (run_one_file(filename) < 0) {
+ error = -1;
+ goto exit;
+ }
+ }
+ fprintf(stderr, "Done %d runs\n", i);
+
+exit:
+ git_vector_free_deep(&corpus_files);
+ return error;
+}