Coverage Report

Created: 2025-07-12 06:53

/src/libgit2/fuzzers/patch_parse_fuzzer.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * libgit2 patch parser 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 "patch.h"
12
#include "patch_parse.h"
13
14
#include "standalone_driver.h"
15
16
12
#define UNUSED(x) (void)(x)
17
18
int LLVMFuzzerInitialize(int *argc, char ***argv)
19
6
{
20
6
  UNUSED(argc);
21
6
  UNUSED(argv);
22
23
6
  if (git_libgit2_init() < 0)
24
0
    abort();
25
26
6
  return 0;
27
6
}
28
29
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
30
2.13k
{
31
2.13k
  if (size) {
32
2.13k
    git_patch *patch = NULL;
33
2.13k
    git_patch_options opts = GIT_PATCH_OPTIONS_INIT;
34
2.13k
    opts.prefix_len = (uint32_t)data[0];
35
2.13k
    git_patch_from_buffer(&patch, (const char *)data + 1, size - 1,
36
2.13k
                          &opts);
37
2.13k
    git_patch_free(patch);
38
2.13k
  }
39
2.13k
  return 0;
40
2.13k
}