]> git.proxmox.com Git - libgit2.git/blob - fuzzers/config_file_fuzzer.c
Add -DUSE_NTLMCLIENT and -DUSE_HTTP_PARSER flags to CMake
[libgit2.git] / fuzzers / config_file_fuzzer.c
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
10 #include "git2.h"
11 #include "config_backend.h"
12
13 #define UNUSED(x) (void)(x)
14
15 int foreach_cb(const git_config_entry *entry, void *payload)
16 {
17 UNUSED(entry);
18 UNUSED(payload);
19
20 return 0;
21 }
22
23 int LLVMFuzzerInitialize(int *argc, char ***argv)
24 {
25 UNUSED(argc);
26 UNUSED(argv);
27
28 if (git_libgit2_init() < 0)
29 abort();
30
31 return 0;
32 }
33
34 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
35 {
36 git_config *cfg = NULL;
37 git_config_backend *backend = NULL;
38 int err = 0;
39
40 if ((err = git_config_new(&cfg)) != 0) {
41 goto out;
42 }
43
44 if ((err = git_config_backend_from_string(&backend, (const char*)data, size)) != 0) {
45 goto out;
46 }
47 if ((err = git_config_add_backend(cfg, backend, 0, NULL, 0)) != 0) {
48 goto out;
49 }
50 /* Now owned by the config */
51 backend = NULL;
52
53 git_config_foreach(cfg, foreach_cb, NULL);
54 out:
55 git_config_backend_free(backend);
56 git_config_free(cfg);
57
58 return 0;
59 }