diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-10-12 12:38:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-12 12:38:06 +0200 |
commit | 814e7acbabc2e756f809057b7746e08839c44cde (patch) | |
tree | f8112f18aaae22fc70011c1444e41b28294fa0c3 /fuzzers/config_file_fuzzer.c | |
parent | 838a2f2918b6d9fad8768d2498575ff5d75c35f0 (diff) | |
parent | 463c21e2c10e82d8e5ba4e3e7e908052f2b739f6 (diff) | |
download | libgit2-814e7acbabc2e756f809057b7746e08839c44cde.tar.gz |
Merge pull request #4842 from nelhage/fuzz-config-memory
config: Port config_file_fuzzer to the new in-memory backend.
Diffstat (limited to 'fuzzers/config_file_fuzzer.c')
-rw-r--r-- | fuzzers/config_file_fuzzer.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/fuzzers/config_file_fuzzer.c b/fuzzers/config_file_fuzzer.c index 30a47bf2e..fa52642ae 100644 --- a/fuzzers/config_file_fuzzer.c +++ b/fuzzers/config_file_fuzzer.c @@ -8,6 +8,7 @@ */ #include <git2.h> +#include "config_backend.h" #include <stdlib.h> #include <stdio.h> @@ -25,9 +26,6 @@ int foreach_cb(const git_config_entry *entry, void *payload) return 0; } -static char path[] = "/tmp/git.XXXXXX"; -static int fd = -1; - int LLVMFuzzerInitialize(int *argc, char ***argv) { UNUSED(argc); @@ -35,10 +33,6 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) if (git_libgit2_init() < 0) abort(); - fd = mkstemp(path); - if (fd < 0) { - abort(); - } return 0; } @@ -46,30 +40,26 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { git_config *cfg = NULL; + git_config_backend *backend = NULL; int err = 0; - size_t total = 0; - if (ftruncate(fd, 0) !=0 ) { - abort(); - } - if (lseek(fd, 0, SEEK_SET) != 0) { - abort(); + if ((err = git_config_new(&cfg)) != 0) { + goto out; } - while (total < size) { - ssize_t written = write(fd, data, size); - if (written < 0 && errno != EINTR) - abort(); - if (written < 0) - continue; - total += written; + if ((err = git_config_backend_from_string(&backend, (const char*)data, size)) != 0) { + goto out; } - - err = git_config_open_ondisk(&cfg, path); - if (err == 0) { - git_config_foreach(cfg, foreach_cb, NULL); - git_config_free(cfg); + if ((err = git_config_add_backend(cfg, backend, 0, NULL, 0)) != 0) { + goto out; } + /* Now owned by the config */ + backend = NULL; + + git_config_foreach(cfg, foreach_cb, NULL); + out: + git_config_backend_free(backend); + git_config_free(cfg); return 0; } |