summaryrefslogtreecommitdiffstats
path: root/fuzzers/patch_parse_fuzzer.c
blob: 2e65a01fd88f0fc2d73475b898f5010c4007eba6 (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
/*
 * libgit2 patch parser 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 "git2.h"
#include "patch.h"
#include "patch_parse.h"

#include "standalone_driver.h"

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

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

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

	return 0;
}

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
	if (size) {
		git_patch *patch = NULL;
		git_patch_options opts = GIT_PATCH_OPTIONS_INIT;
		opts.prefix_len = (uint32_t)data[0];
		git_patch_from_buffer(&patch, (const char *)data + 1, size - 1,
		                      &opts);
		git_patch_free(patch);
	}
	return 0;
}