]> git.proxmox.com Git - libgit2.git/blob - fuzzers/objects_fuzzer.c
Update upstream source from tag 'upstream/1.5.0+ds'
[libgit2.git] / fuzzers / objects_fuzzer.c
1 /*
2 * libgit2 packfile 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 "git2.h"
11 #include "object.h"
12
13 #include "standalone_driver.h"
14
15 #define UNUSED(x) (void)(x)
16
17 int LLVMFuzzerInitialize(int *argc, char ***argv)
18 {
19 UNUSED(argc);
20 UNUSED(argv);
21
22 if (git_libgit2_init() < 0)
23 abort();
24
25 return 0;
26 }
27
28 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
29 {
30 const git_object_t types[] = {
31 GIT_OBJECT_BLOB, GIT_OBJECT_TREE, GIT_OBJECT_COMMIT, GIT_OBJECT_TAG
32 };
33 git_object *object = NULL;
34 size_t i;
35
36 /*
37 * Brute-force parse this as every object type. We want
38 * to stress the parsing logic anyway, so this is fine
39 * to do.
40 */
41 for (i = 0; i < ARRAY_SIZE(types); i++) {
42 if (git_object__from_raw(&object, (const char *) data, size, types[i]) < 0)
43 continue;
44 git_object_free(object);
45 object = NULL;
46 }
47
48 return 0;
49 }