| 1 |
/* |
| 2 |
* Copyright (C) the libgit2 contributors. All rights reserved. |
| 3 |
* |
| 4 |
* This file is part of libgit2, distributed under the GNU GPL v2 with |
| 5 |
* a Linking Exception. For full terms see the included COPYING file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <string.h> |
| 11 |
|
| 12 |
#include "git2.h" |
| 13 |
#include "futils.h" |
| 14 |
|
| 15 |
#include "fuzzer_utils.h" |
| 16 |
|
| 17 |
void fuzzer_git_abort(const char *op) |
| 18 |
{ |
| 19 |
const git_error *err = git_error_last(); |
| 20 |
fprintf(stderr, "unexpected libgit error: %s: %s\n", |
| 21 |
op, err ? err->message : "<none>"); |
| 22 |
abort(); |
| 23 |
} |
| 24 |
|
| 25 |
git_repository *fuzzer_repo_init(void) |
| 26 |
{ |
| 27 |
git_repository *repo; |
| 28 |
|
| 29 |
#if defined(_WIN32) |
| 30 |
char tmpdir[MAX_PATH], path[MAX_PATH]; |
| 31 |
|
| 32 |
if (GetTempPath((DWORD)sizeof(tmpdir), tmpdir) == 0) |
| 33 |
abort(); |
| 34 |
|
| 35 |
if (GetTempFileName(tmpdir, "lg2", 1, path) == 0) |
| 36 |
abort(); |
| 37 |
|
| 38 |
if (git_futils_mkdir(path, 0700, 0) < 0) |
| 39 |
abort(); |
| 40 |
#else |
| 41 |
char path[] = "/tmp/git2.XXXXXX"; |
| 42 |
|
| 43 |
if (mkdtemp(path) != path) |
| 44 |
abort(); |
| 45 |
#endif |
| 46 |
|
| 47 |
if (git_repository_init(&repo, path, 1) < 0) |
| 48 |
fuzzer_git_abort("git_repository_init"); |
| 49 |
|
| 50 |
return repo; |
| 51 |
} |