File: fuzzer_utils.c

package info (click to toggle)
libgit2 1.9.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 60,804 kB
  • sloc: ansic: 203,436; javascript: 2,458; sh: 1,763; python: 384; perl: 99; php: 65; makefile: 33
file content (51 lines) | stat: -rw-r--r-- 1,032 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "git2.h"
#include "futils.h"

#include "fuzzer_utils.h"

void fuzzer_git_abort(const char *op)
{
	const git_error *err = git_error_last();
	fprintf(stderr, "unexpected libgit error: %s: %s\n",
		op, err ? err->message : "<none>");
	abort();
}

git_repository *fuzzer_repo_init(void)
{
	git_repository *repo;

#if defined(_WIN32)
	char tmpdir[MAX_PATH], path[MAX_PATH];

	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_repository_init(&repo, path, 1) < 0)
		fuzzer_git_abort("git_repository_init");

	return repo;
}