summaryrefslogtreecommitdiff
path: root/fuzzers
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-06-28 10:47:37 +0200
committerPatrick Steinhardt <ps@pks.im>2019-07-05 11:58:32 +0200
commit48d563286c788f344dd97feba1b06da6b4b42ac0 (patch)
tree6dfeedc4e2aebb5da266328bdb340d57dba14932 /fuzzers
parent398412ccd3f982e2bc1de16d87bd00f27580c256 (diff)
downloadlibgit2-48d563286c788f344dd97feba1b06da6b4b42ac0.tar.gz
fuzzers: implement `mkdtemp` alternative for Win32
The `mkdtemp` function is not available on Windows, so our download_refs fuzzer will fail to compile on Windows. Provide an alternative implementation to fix it.
Diffstat (limited to 'fuzzers')
-rw-r--r--fuzzers/download_refs_fuzzer.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/fuzzers/download_refs_fuzzer.c b/fuzzers/download_refs_fuzzer.c
index 93f1b49b3..2b70dd053 100644
--- a/fuzzers/download_refs_fuzzer.c
+++ b/fuzzers/download_refs_fuzzer.c
@@ -15,6 +15,7 @@
#include "git2.h"
#include "git2/sys/transport.h"
+#include "fileops.h"
#define UNUSED(x) (void)(x)
@@ -166,10 +167,23 @@ void fuzzer_git_abort(const char *op)
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
- char tmp[] = "/tmp/git2.XXXXXX";
+#if defined(_WIN32)
+ char tmpdir[MAX_PATH], path[MAX_PATH];
- UNUSED(argc);
- UNUSED(argv);
+ 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_libgit2_init() < 0)
abort();
@@ -177,10 +191,10 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
if (git_libgit2_opts(GIT_OPT_SET_PACK_MAX_OBJECTS, 10000000) < 0)
abort();
- if (mkdtemp(tmp) != tmp)
- abort();
+ UNUSED(argc);
+ UNUSED(argv);
- if (git_repository_init(&repo, tmp, 1) < 0)
+ if (git_repository_init(&repo, path, 1) < 0)
fuzzer_git_abort("git_repository_init");
return 0;