Coverage Report

Created: 2026-02-26 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libgit2/fuzzers/config_file_fuzzer.c
Line
Count
Source
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
#include "standalone_driver.h"
14
15
29.9k
#define UNUSED(x) (void)(x)
16
17
static int foreach_cb(const git_config_entry *entry, void *payload)
18
14.9k
{
19
14.9k
  UNUSED(entry);
20
14.9k
  UNUSED(payload);
21
22
14.9k
  return 0;
23
14.9k
}
24
25
int LLVMFuzzerInitialize(int *argc, char ***argv)
26
6
{
27
6
  UNUSED(argc);
28
6
  UNUSED(argv);
29
30
6
  if (git_libgit2_init() < 0)
31
0
    abort();
32
33
6
  return 0;
34
6
}
35
36
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
37
1.51k
{
38
1.51k
  git_config *cfg = NULL;
39
1.51k
  git_config_backend *backend = NULL;
40
1.51k
  int err = 0;
41
42
1.51k
  if ((err = git_config_new(&cfg)) != 0) {
43
0
    goto out;
44
0
  }
45
46
1.51k
  if ((err = git_config_backend_from_string(&backend, (const char*)data, size, NULL)) != 0) {
47
0
    goto out;
48
0
  }
49
1.51k
  if ((err = git_config_add_backend(cfg, backend, 0, NULL, 0)) != 0) {
50
755
    goto out;
51
755
  }
52
  /* Now owned by the config */
53
759
  backend = NULL;
54
55
759
  git_config_foreach(cfg, foreach_cb, NULL);
56
1.51k
 out:
57
1.51k
  git_config_backend_free(backend);
58
1.51k
  git_config_free(cfg);
59
60
1.51k
  return 0;
61
759
}