File: config_file_fuzzer.c

package info (click to toggle)
libgit2 1.1.0%2Bdfsg.1-4%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 53,324 kB
  • sloc: ansic: 173,567; sh: 562; python: 351; php: 65; makefile: 50
file content (59 lines) | stat: -rw-r--r-- 1,144 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
52
53
54
55
56
57
58
59
/*
 * libgit2 config file parser fuzz 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 "config_backend.h"

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

int foreach_cb(const git_config_entry *entry, void *payload)
{
	UNUSED(entry);
	UNUSED(payload);

	return 0;
}

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)
{
	git_config *cfg = NULL;
	git_config_backend *backend = NULL;
	int err = 0;

	if ((err = git_config_new(&cfg)) != 0) {
		goto out;
	}

	if ((err = git_config_backend_from_string(&backend, (const char*)data, size)) != 0) {
		goto out;
	}
	if ((err = git_config_add_backend(cfg, backend, 0, NULL, 0)) != 0) {
		goto out;
	}
	/* Now owned by the config */
	backend = NULL;

	git_config_foreach(cfg, foreach_cb, NULL);
 out:
	git_config_backend_free(backend);
	git_config_free(cfg);

	return 0;
}