]>
git.proxmox.com Git - libgit2.git/blob - fuzzers/standalone_driver.c
2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
14 extern int LLVMFuzzerTestOneInput(const unsigned char *data
, size_t size
);
15 extern int LLVMFuzzerInitialize(int *argc
, char ***argv
);
17 static int run_one_file(const char *filename
)
19 git_buf buf
= GIT_BUF_INIT
;
22 if (git_futils_readbuffer(&buf
, filename
) < 0) {
23 fprintf(stderr
, "Failed to read %s: %s\n", filename
, git_error_last()->message
);
28 LLVMFuzzerTestOneInput((const unsigned char *)buf
.ptr
, buf
.size
);
30 git_buf_dispose(&buf
);
34 int main(int argc
, char **argv
)
36 git_vector corpus_files
= GIT_VECTOR_INIT
;
37 char *filename
= NULL
;
41 if (git_libgit2_init() < 0) {
42 fprintf(stderr
, "Failed to initialize libgit2\n");
47 fprintf(stderr
, "Usage: %s <corpus directory>\n", argv
[0]);
52 fprintf(stderr
, "Running %s against %s\n", argv
[0], argv
[1]);
53 LLVMFuzzerInitialize(&argc
, &argv
);
55 if (git_path_dirload(&corpus_files
, argv
[1], 0, 0x0) < 0) {
56 fprintf(stderr
, "Failed to scan corpus directory '%s': %s\n",
57 argv
[1], git_error_last()->message
);
61 git_vector_foreach(&corpus_files
, i
, filename
) {
62 fprintf(stderr
, "\tRunning %s...\n", filename
);
63 if (run_one_file(filename
) < 0) {
68 fprintf(stderr
, "Done %d runs\n", i
);
71 git_vector_free_deep(&corpus_files
);
72 git_libgit2_shutdown();