summaryrefslogtreecommitdiffstats
path: root/fuzzers/fuzzer_utils.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 05:03:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 05:03:04 +0000
commitb88736462df2c86a83f01dcc260b5463205819d2 (patch)
treeb1a9a5a5392a52ec4e5f60fb4b45083cf7fd65b0 /fuzzers/fuzzer_utils.c
parentAdding upstream version 1.7.2+ds. (diff)
downloadlibgit2-b88736462df2c86a83f01dcc260b5463205819d2.tar.xz
libgit2-b88736462df2c86a83f01dcc260b5463205819d2.zip
Adding upstream version 1.8.1+ds.upstream/1.8.1+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fuzzers/fuzzer_utils.c')
-rw-r--r--fuzzers/fuzzer_utils.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/fuzzers/fuzzer_utils.c b/fuzzers/fuzzer_utils.c
new file mode 100644
index 0000000..cde5065
--- /dev/null
+++ b/fuzzers/fuzzer_utils.c
@@ -0,0 +1,51 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "git2.h"
+#include "futils.h"
+
+#include "fuzzer_utils.h"
+
+void fuzzer_git_abort(const char *op)
+{
+ const git_error *err = git_error_last();
+ fprintf(stderr, "unexpected libgit error: %s: %s\n",
+ op, err ? err->message : "<none>");
+ abort();
+}
+
+git_repository *fuzzer_repo_init(void)
+{
+ git_repository *repo;
+
+#if defined(_WIN32)
+ char tmpdir[MAX_PATH], path[MAX_PATH];
+
+ if (GetTempPath((DWORD)sizeof(tmpdir), tmpdir) == 0)
+ abort();
+
+ if (GetTempFileName(tmpdir, "lg2", 1, path) == 0)
+ abort();
+
+ if (git_futils_mkdir(path, 0700, 0) < 0)
+ abort();
+#else
+ char path[] = "/tmp/git2.XXXXXX";
+
+ if (mkdtemp(path) != path)
+ abort();
+#endif
+
+ if (git_repository_init(&repo, path, 1) < 0)
+ fuzzer_git_abort("git_repository_init");
+
+ return repo;
+}