/src/libgit2/fuzzers/revparse_fuzzer.c
Line | Count | Source |
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 | 4 | #define UNUSED(x) (void)(x) |
19 | | |
20 | | static git_repository *repo; |
21 | | |
22 | | int LLVMFuzzerInitialize(int *argc, char ***argv) |
23 | 2 | { |
24 | 2 | UNUSED(argc); |
25 | 2 | UNUSED(argv); |
26 | | |
27 | 2 | if (git_libgit2_init() < 0) |
28 | 0 | abort(); |
29 | | |
30 | 2 | if (git_libgit2_opts(GIT_OPT_SET_PACK_MAX_OBJECTS, 10000000) < 0) |
31 | 0 | abort(); |
32 | | |
33 | 2 | repo = fuzzer_repo_init(); |
34 | 2 | return 0; |
35 | 2 | } |
36 | | |
37 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
38 | 11.1k | { |
39 | 11.1k | git_object *obj = NULL; |
40 | 11.1k | char *c; |
41 | | |
42 | 11.1k | if ((c = calloc(1, size + 1)) == NULL) |
43 | 0 | abort(); |
44 | | |
45 | 11.1k | memcpy(c, data, size); |
46 | | |
47 | 11.1k | git_revparse_single(&obj, repo, c); |
48 | 11.1k | git_object_free(obj); |
49 | 11.1k | free(c); |
50 | | |
51 | 11.1k | return 0; |
52 | 11.1k | } |