diff options
author | Nelson Elhage <nelhage@nelhage.com> | 2018-07-22 23:48:53 +0000 |
---|---|---|
committer | Nelson Elhage <nelhage@nelhage.com> | 2018-08-05 03:13:49 +0000 |
commit | 1a8e22e846cf6ffcc794c4cd6883c2488447f304 (patch) | |
tree | f29953263074aaf0ab6512fd1e5d7bb31fc0dea1 /fuzzers | |
parent | 64138b70e10b9812af8f944e83747aa51da9a920 (diff) | |
download | libgit2-1a8e22e846cf6ffcc794c4cd6883c2488447f304.tar.gz |
Add a config file fuzzer
Diffstat (limited to 'fuzzers')
-rw-r--r-- | fuzzers/config_file_fuzzer.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/fuzzers/config_file_fuzzer.c b/fuzzers/config_file_fuzzer.c new file mode 100644 index 000000000..eafcd1093 --- /dev/null +++ b/fuzzers/config_file_fuzzer.c @@ -0,0 +1,41 @@ +#include <git2.h> + +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <limits.h> + +int foreach_cb(const git_config_entry *entry, void *payload) { + return 0; +} + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + static int fd = -1; + static char path[] = "/tmp/git.XXXXXX"; + if (fd < 0) { + git_libgit2_init(); + fd = mkstemp(path); + if (fd < 0) { + abort(); + } + } + if (ftruncate(fd, 0) !=0 ) { + abort(); + } + if (lseek(fd, 0, SEEK_SET) != 0) { + abort(); + } + if (write(fd, data, size) != size) { + abort(); + } + + git_config *cfg; + int err = git_config_open_ondisk(&cfg, path); + if (err == 0) { + git_config_foreach(cfg, foreach_cb, NULL); + git_config_free(cfg); + } + + return 0; +} |