diff options
author | Nelson Elhage <nelhage@nelhage.com> | 2018-08-14 04:01:04 +0000 |
---|---|---|
committer | Nelson Elhage <nelhage@nelhage.com> | 2018-08-14 04:01:04 +0000 |
commit | 298f5df6ffde6ac526dcf48cc60d495c5cfbff93 (patch) | |
tree | cfa9db5d3606884477ba815594c1380bfd86eedb /fuzzers | |
parent | 8189642d244e0b55d5202fa775c3c9a8f54eea83 (diff) | |
download | libgit2-298f5df6ffde6ac526dcf48cc60d495c5cfbff93.tar.gz |
Further review comments, fix the build
Diffstat (limited to 'fuzzers')
-rw-r--r-- | fuzzers/config_file_fuzzer.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/fuzzers/config_file_fuzzer.c b/fuzzers/config_file_fuzzer.c index 869812029..fd604fa34 100644 --- a/fuzzers/config_file_fuzzer.c +++ b/fuzzers/config_file_fuzzer.c @@ -5,34 +5,50 @@ #include <unistd.h> #include <limits.h> +#define UNUSED(x) (void)(x) + int foreach_cb(const git_config_entry *entry, void *payload) { + UNUSED(entry); + UNUSED(payload); + return 0; } -int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +static char path[] = "/tmp/git.XXXXXX"; +static int fd = -1; + +int LLVMFuzzerInitialize(int *argc, char ***argv) { - static int fd = -1; - static char path[] = "/tmp/git.XXXXXX"; + UNUSED(argc); + UNUSED(argv); + + if (git_libgit2_init() < 0) + abort(); + fd = mkstemp(path); if (fd < 0) { - git_libgit2_init(); - fd = mkstemp(path); - if (fd < 0) { - abort(); - } + abort(); } + + return 0; +} + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + git_config *cfg = NULL; + int err = 0; + if (ftruncate(fd, 0) !=0 ) { abort(); } if (lseek(fd, 0, SEEK_SET) != 0) { abort(); } - if (write(fd, data, size) != size) { + if ((size_t)write(fd, data, size) != size) { abort(); } - git_config *cfg; - int err = git_config_open_ondisk(&cfg, path); + err = git_config_open_ondisk(&cfg, path); if (err == 0) { git_config_foreach(cfg, foreach_cb, NULL); git_config_free(cfg); |