Skip to content

Commit 48d5632

Browse files
committed
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.
1 parent 398412c commit 48d5632

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

fuzzers/download_refs_fuzzer.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "git2.h"
1717
#include "git2/sys/transport.h"
18+
#include "fileops.h"
1819

1920
#define UNUSED(x) (void)(x)
2021

@@ -166,21 +167,34 @@ void fuzzer_git_abort(const char *op)
166167

167168
int LLVMFuzzerInitialize(int *argc, char ***argv)
168169
{
169-
char tmp[] = "/tmp/git2.XXXXXX";
170+
#if defined(_WIN32)
171+
char tmpdir[MAX_PATH], path[MAX_PATH];
170172

171-
UNUSED(argc);
172-
UNUSED(argv);
173+
if (GetTempPath((DWORD)sizeof(tmpdir), tmpdir) == 0)
174+
abort();
175+
176+
if (GetTempFileName(tmpdir, "lg2", 1, path) == 0)
177+
abort();
178+
179+
if (git_futils_mkdir(path, 0700, 0) < 0)
180+
abort();
181+
#else
182+
char path[] = "/tmp/git2.XXXXXX";
183+
184+
if (mkdtemp(path) != path)
185+
abort();
186+
#endif
173187

174188
if (git_libgit2_init() < 0)
175189
abort();
176190

177191
if (git_libgit2_opts(GIT_OPT_SET_PACK_MAX_OBJECTS, 10000000) < 0)
178192
abort();
179193

180-
if (mkdtemp(tmp) != tmp)
181-
abort();
194+
UNUSED(argc);
195+
UNUSED(argv);
182196

183-
if (git_repository_init(&repo, tmp, 1) < 0)
197+
if (git_repository_init(&repo, path, 1) < 0)
184198
fuzzer_git_abort("git_repository_init");
185199

186200
return 0;

0 commit comments

Comments
 (0)