summaryrefslogtreecommitdiffstats
path: root/fuzzers/revparse_fuzzer.c
blob: 37c22e2221cd5625b1b51b925c0312ab83185d94 (plain)
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
52
/*
 * libgit2 revparse fuzzer target.
 *
 * 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 <string.h>

#include "git2.h"

#include "standalone_driver.h"
#include "fuzzer_utils.h"

#define UNUSED(x) (void)(x)

static git_repository *repo;

int LLVMFuzzerInitialize(int *argc, char ***argv)
{
	UNUSED(argc);
	UNUSED(argv);

	if (git_libgit2_init() < 0)
		abort();

	if (git_libgit2_opts(GIT_OPT_SET_PACK_MAX_OBJECTS, 10000000) < 0)
		abort();

	repo = fuzzer_repo_init();
	return 0;
}

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
	git_object *obj = NULL;
	char *c;

	if ((c = calloc(1, size + 1)) == NULL)
		abort();

	memcpy(c, data, size);

	git_revparse_single(&obj, repo, c);
	git_object_free(obj);
	free(c);

	return 0;
}