Commit 48d56328 by Patrick Steinhardt

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.
parent 398412cc
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment