summaryrefslogtreecommitdiff
path: root/fuzzers
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-06-28 12:10:51 +0200
committerPatrick Steinhardt <ps@pks.im>2019-07-05 11:58:33 +0200
commit9d43d45b21ef45895a5b7f10d690ec8543e07709 (patch)
tree108438115df5a93d4a6c70853a5c981c2353ac67 /fuzzers
parenta6b2fffd46ff72dc3a976dcbdf5024ef0964106c (diff)
downloadlibgit2-9d43d45b21ef45895a5b7f10d690ec8543e07709.tar.gz
fuzzers: use `git_buf_printf` instead of `snprintf`
The `snprintf` function does not exist on Win32, it only has `_snprintf_s` available. Let's just avoid any cross-platform hassle and use our own `git_buf` functionality instead.
Diffstat (limited to 'fuzzers')
-rw-r--r--fuzzers/packfile_fuzzer.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c
index b42c6f5df..672f5577a 100644
--- a/fuzzers/packfile_fuzzer.c
+++ b/fuzzers/packfile_fuzzer.c
@@ -16,6 +16,7 @@
#include "git2.h"
#include "git2/sys/mempack.h"
#include "common.h"
+#include "buffer.h"
static git_odb *odb = NULL;
static git_odb_backend *mempack = NULL;
@@ -54,12 +55,11 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
- git_indexer *indexer = NULL;
git_indexer_progress stats = {0, 0};
+ git_indexer *indexer = NULL;
+ git_buf path = GIT_BUF_INIT;
+ git_oid oid;
bool append_hash = false;
- git_oid id;
- char hash[GIT_OID_HEXSZ + 1] = {0};
- char path[GIT_PATH_MAX];
if (size == 0)
return 0;
@@ -70,7 +70,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
git_mempack_reset(mempack);
- if (git_odb_write(&id, odb, base_obj, base_obj_len, GIT_OBJECT_BLOB) < 0) {
+ if (git_odb_write(&oid, odb, base_obj, base_obj_len, GIT_OBJECT_BLOB) < 0) {
fprintf(stderr, "Failed to add an object to the odb\n");
abort();
}
@@ -92,7 +92,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (git_indexer_append(indexer, data, size, &stats) < 0)
goto cleanup;
if (append_hash) {
- git_oid oid;
if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort();
@@ -104,19 +103,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (git_indexer_commit(indexer, &stats) < 0)
goto cleanup;
- /*
- * We made it! We managed to produce a valid packfile.
- * Let's clean it up.
- */
- git_oid_fmt(hash, git_indexer_hash(indexer));
- printf("Generated packfile %s\n", hash);
- snprintf(path, sizeof(path), "pack-%s.idx", hash);
- p_unlink(path);
- snprintf(path, sizeof(path), "pack-%s.pack", hash);
- p_unlink(path);
+ if (git_buf_printf(&path, "pack-%s.idx", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
+ goto cleanup;
+ p_unlink(git_buf_cstr(&path));
+
+ git_buf_clear(&path);
+
+ if (git_buf_printf(&path, "pack-%s.pack", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
+ goto cleanup;
+ p_unlink(git_buf_cstr(&path));
cleanup:
git_mempack_reset(mempack);
git_indexer_free(indexer);
+ git_buf_dispose(&path);
return 0;
}