Debian Codegraph @

fuzzers/corpora/patch_parse/patch_fuzzer-patch.diff

raw
1 diff --git a/fuzzers/patch_fuzzer.c b/fuzzers/patch_fuzzer.c
2 new file mode 100644
3 index 000000000..76186b6fb
4 --- /dev/null
5 +++ b/fuzzers/patch_fuzzer.c
6 @@ -0,0 +1,39 @@
7 +/*
8 + * libgit2 patch fuzzer target.
9 + *
10 + * Copyright (C) the libgit2 contributors. All rights reserved.
11 + *
12 + * This file is part of libgit2, distributed under the GNU GPL v2 with
13 + * a Linking Exception. For full terms see the included COPYING file.
14 + */
15 +
16 +#include "git2.h"
17 +#include "patch.h"
18 +#include "patch_parse.h"
19 +
20 +#define UNUSED(x) (void)(x)
21 +
22 +int LLVMFuzzerInitialize(int *argc, char ***argv)
23 +{
24 + UNUSED(argc);
25 + UNUSED(argv);
26 +
27 + if (git_libgit2_init() < 0)
28 + abort();
29 +
30 + return 0;
31 +}
32 +
33 +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
34 +{
35 + if (size < 1) {
36 + return 0;
37 + }
38 + git_patch* patch;
39 + git_patch_options opts = {(uint32_t)data[0]};
40 + int status = git_patch_from_buffer(&patch, (const char*)data+1, size-1, &opts);
41 + if (status == 0 && patch) {
42 + git_patch_free(patch);
43 + }
44 + return 0;
45 +}