summaryrefslogtreecommitdiff
path: root/fuzzers/commit_graph_fuzzer.c
diff options
context:
space:
mode:
Diffstat (limited to 'fuzzers/commit_graph_fuzzer.c')
-rw-r--r--fuzzers/commit_graph_fuzzer.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/fuzzers/commit_graph_fuzzer.c b/fuzzers/commit_graph_fuzzer.c
index b41816ed9..1c46d78c7 100644
--- a/fuzzers/commit_graph_fuzzer.c
+++ b/fuzzers/commit_graph_fuzzer.c
@@ -11,12 +11,14 @@
#include "git2.h"
-#include "buffer.h"
#include "common.h"
+#include "str.h"
#include "futils.h"
#include "hash.h"
#include "commit_graph.h"
+#include "standalone_driver.h"
+
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
GIT_UNUSED(argc);
@@ -33,7 +35,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
git_commit_graph_file file = {{0}};
git_commit_graph_entry e;
- git_buf commit_graph_buf = GIT_BUF_INIT;
+ git_str commit_graph_buf = GIT_STR_INIT;
+ unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}};
bool append_hash = false;
@@ -50,22 +53,24 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size -= 4;
if (append_hash) {
- if (git_buf_init(&commit_graph_buf, size + sizeof(oid)) < 0)
+ if (git_str_init(&commit_graph_buf, size + GIT_HASH_SHA1_SIZE) < 0)
goto cleanup;
- if (git_hash_buf(&oid, data, size) < 0) {
+ if (git_hash_buf(hash, data, size, GIT_HASH_ALGORITHM_SHA1) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort();
}
memcpy(commit_graph_buf.ptr, data, size);
- memcpy(commit_graph_buf.ptr + size, &oid, sizeof(oid));
+ memcpy(commit_graph_buf.ptr + size, hash, GIT_HASH_SHA1_SIZE);
+
+ memcpy(oid.id, hash, GIT_OID_RAWSZ);
} else {
- git_buf_attach_notowned(&commit_graph_buf, (char *)data, size);
+ git_str_attach_notowned(&commit_graph_buf, (char *)data, size);
}
if (git_commit_graph_file_parse(
&file,
- (const unsigned char *)git_buf_cstr(&commit_graph_buf),
- git_buf_len(&commit_graph_buf))
+ (const unsigned char *)git_str_cstr(&commit_graph_buf),
+ git_str_len(&commit_graph_buf))
< 0)
goto cleanup;
@@ -75,6 +80,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
cleanup:
git_commit_graph_file_close(&file);
- git_buf_dispose(&commit_graph_buf);
+ git_str_dispose(&commit_graph_buf);
return 0;
}