Coverage Report

Created: 2025-06-20 06:36

/src/libgit2/fuzzers/fuzzer_utils.c
Line
Count
Source (jump to first uncovered line)
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
0
{
19
0
  const git_error *err = git_error_last();
20
0
  fprintf(stderr, "unexpected libgit error: %s: %s\n",
21
0
    op, err ? err->message : "<none>");
22
0
  abort();
23
0
}
24
25
git_repository *fuzzer_repo_init(void)
26
0
{
27
0
  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
0
  char path[] = "/tmp/git2.XXXXXX";
42
43
0
  if (mkdtemp(path) != path)
44
0
    abort();
45
0
#endif
46
47
0
  if (git_repository_init(&repo, path, 1) < 0)
48
0
    fuzzer_git_abort("git_repository_init");
49
50
0
  return repo;
51
0
}