summaryrefslogtreecommitdiff
path: root/fuzzers
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-10-02 13:50:12 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-10-02 16:34:47 -0400
commitf0a0916028ef1c599030f513c0685b77d74e6c21 (patch)
tree24a3a98bfcef9108b1ed07fb586d7364a62fb24d /fuzzers
parent923364c58eaca0c54f09def3292dff848975906c (diff)
downloadlibgit2-f0a0916028ef1c599030f513c0685b77d74e6c21.tar.gz
fuzzers: use updated hash functionsethomson/oid
Diffstat (limited to 'fuzzers')
-rw-r--r--fuzzers/commit_graph_fuzzer.c9
-rw-r--r--fuzzers/midx_fuzzer.c9
2 files changed, 12 insertions, 6 deletions
diff --git a/fuzzers/commit_graph_fuzzer.c b/fuzzers/commit_graph_fuzzer.c
index b41816ed9..39b520882 100644
--- a/fuzzers/commit_graph_fuzzer.c
+++ b/fuzzers/commit_graph_fuzzer.c
@@ -34,6 +34,7 @@ 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;
+ unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}};
bool append_hash = false;
@@ -50,14 +51,16 @@ 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_buf_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);
}
diff --git a/fuzzers/midx_fuzzer.c b/fuzzers/midx_fuzzer.c
index e67873faa..9739f0a40 100644
--- a/fuzzers/midx_fuzzer.c
+++ b/fuzzers/midx_fuzzer.c
@@ -34,6 +34,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
git_midx_file idx = {{0}};
git_midx_entry e;
git_buf midx_buf = GIT_BUF_INIT;
+ unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}};
bool append_hash = false;
@@ -50,14 +51,16 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size -= 4;
if (append_hash) {
- if (git_buf_init(&midx_buf, size + sizeof(oid)) < 0)
+ if (git_buf_init(&midx_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(midx_buf.ptr, data, size);
- memcpy(midx_buf.ptr + size, &oid, sizeof(oid));
+ memcpy(midx_buf.ptr + size, hash, GIT_HASH_SHA1_SIZE);
+
+ memcpy(oid.id, hash, GIT_OID_RAWSZ);
} else {
git_buf_attach_notowned(&midx_buf, (char *)data, size);
}