]>
Commit | Line | Data |
---|---|---|
ac3d33df JK |
1 | /* |
2 | * libgit2 config file parser fuzz 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 | ||
22a2d3d5 | 10 | #include "git2.h" |
ac3d33df JK |
11 | #include "config_backend.h" |
12 | ||
e579e0f7 MB |
13 | #include "standalone_driver.h" |
14 | ||
ac3d33df JK |
15 | #define UNUSED(x) (void)(x) |
16 | ||
e579e0f7 | 17 | static int foreach_cb(const git_config_entry *entry, void *payload) |
ac3d33df JK |
18 | { |
19 | UNUSED(entry); | |
20 | UNUSED(payload); | |
21 | ||
22 | return 0; | |
23 | } | |
24 | ||
25 | int LLVMFuzzerInitialize(int *argc, char ***argv) | |
26 | { | |
27 | UNUSED(argc); | |
28 | UNUSED(argv); | |
29 | ||
30 | if (git_libgit2_init() < 0) | |
31 | abort(); | |
32 | ||
33 | return 0; | |
34 | } | |
35 | ||
36 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | |
37 | { | |
38 | git_config *cfg = NULL; | |
39 | git_config_backend *backend = NULL; | |
40 | int err = 0; | |
41 | ||
42 | if ((err = git_config_new(&cfg)) != 0) { | |
43 | goto out; | |
44 | } | |
45 | ||
46 | if ((err = git_config_backend_from_string(&backend, (const char*)data, size)) != 0) { | |
47 | goto out; | |
48 | } | |
49 | if ((err = git_config_add_backend(cfg, backend, 0, NULL, 0)) != 0) { | |
50 | goto out; | |
51 | } | |
52 | /* Now owned by the config */ | |
53 | backend = NULL; | |
54 | ||
55 | git_config_foreach(cfg, foreach_cb, NULL); | |
56 | out: | |
57 | git_config_backend_free(backend); | |
58 | git_config_free(cfg); | |
59 | ||
60 | return 0; | |
61 | } |