summaryrefslogtreecommitdiff
path: root/fuzzers
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-07-20 11:07:47 +0200
committerPatrick Steinhardt <ps@pks.im>2018-08-03 09:50:35 +0200
commitde53972f65d3dc58f319f9c3a69af6543225a4a0 (patch)
tree4a5d5bbc993d94fb2e4a50345d567067cc64bbcd /fuzzers
parent12804c4600d3aef879ac09b50563f9bf1efea540 (diff)
downloadlibgit2-de53972f65d3dc58f319f9c3a69af6543225a4a0.tar.gz
fuzzers: avoid use of libgit2 internals in packfile_raw
The packfile_raw fuzzer is using some internal APIs from libgit2, which makes it hard to compile it as part of the oss-fuzz project. As oss-fuzz requires us to link against the C++ FuzzingEngine library, we cannot use "-DBUILD_FUZZERS=ON" directly but instead have to first compile an object from our fuzzers and then link against the C++ library. Compiling the fuzzer objects thus requires an external invocation of CC, and we certainly don't want to do further black magic by adding libgit2's private source directory to the header include path. To fix the issue, convert the code to not use any internal APIs. Besides some headers which we have to add now, this also requires us to change to the hashing function of the ODB. Note that this will change the hashing result, as we have previously not prepended the object header to the data that is to be hashed. But this shouldn't matter in practice, as we don't care for the hash value anyway.
Diffstat (limited to 'fuzzers')
-rw-r--r--fuzzers/packfile_fuzzer.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c
index 54d3e6144..e7708b9be 100644
--- a/fuzzers/packfile_fuzzer.c
+++ b/fuzzers/packfile_fuzzer.c
@@ -10,12 +10,14 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+#include <limits.h>
+#include <unistd.h>
-#include "fileops.h"
-#include "hash.h"
#include "git2.h"
#include "git2/sys/mempack.h"
+#define UNUSED(x) (void)(x)
+
static git_odb *odb = NULL;
static git_odb_backend *mempack = NULL;
@@ -25,8 +27,8 @@ static const unsigned int base_obj_len = 2;
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
- GIT_UNUSED(argc);
- GIT_UNUSED(argv);
+ UNUSED(argc);
+ UNUSED(argv);
if (git_libgit2_init() < 0) {
fprintf(stderr, "Failed to initialize libgit2\n");
abort();
@@ -87,7 +89,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto cleanup;
if (append_hash) {
git_oid oid;
- if (git_hash_buf(&oid, data, size) < 0) {
+ if (git_odb_hash(&oid, data, size, GIT_OBJ_BLOB) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort();
}