Debian Codegraph @

fuzzers/revparse_fuzzer.c

raw
1 /*
2 * libgit2 revparse fuzzer target.
3 *
4 * Copyright (C) the libgit2 contributors. All rights reserved.
5 *
6 * This file is part of libgit2, distributed under the GNU GPL v2 with
7 * a Linking Exception. For full terms see the included COPYING file.
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12
13 #include "git2.h"
14
15 #include "standalone_driver.h"
16 #include "fuzzer_utils.h"
17
18 #define UNUSED(x) (void)(x)
19
20 static git_repository *repo;
21
22 int LLVMFuzzerInitialize(int *argc, char ***argv)
23 {
24 UNUSED(argc);
25 UNUSED(argv);
26
27 if (git_libgit2_init() < 0)
28 abort();
29
30 if (git_libgit2_opts(GIT_OPT_SET_PACK_MAX_OBJECTS, 10000000) < 0)
31 abort();
32
33 repo = fuzzer_repo_init();
34 return 0;
35 }
36
37 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
38 {
39 git_object *obj = NULL;
40 char *c;
41
42 if ((c = calloc(1, size + 1)) == NULL)
43 abort();
44
45 memcpy(c, data, size);
46
47 git_revparse_single(&obj, repo, c);
48 git_object_free(obj);
49 free(c);
50
51 return 0;
52 }