Skip to content

Commit 298f5df

Browse files
committed
Further review comments, fix the build
1 parent 8189642 commit 298f5df

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

fuzzers/config_file_fuzzer.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,50 @@
55
#include <unistd.h>
66
#include <limits.h>
77

8+
#define UNUSED(x) (void)(x)
9+
810
int foreach_cb(const git_config_entry *entry, void *payload)
911
{
12+
UNUSED(entry);
13+
UNUSED(payload);
14+
1015
return 0;
1116
}
1217

13-
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
18+
static char path[] = "/tmp/git.XXXXXX";
19+
static int fd = -1;
20+
21+
int LLVMFuzzerInitialize(int *argc, char ***argv)
1422
{
15-
static int fd = -1;
16-
static char path[] = "/tmp/git.XXXXXX";
23+
UNUSED(argc);
24+
UNUSED(argv);
25+
26+
if (git_libgit2_init() < 0)
27+
abort();
28+
fd = mkstemp(path);
1729
if (fd < 0) {
18-
git_libgit2_init();
19-
fd = mkstemp(path);
20-
if (fd < 0) {
21-
abort();
22-
}
30+
abort();
2331
}
32+
33+
return 0;
34+
}
35+
36+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
37+
{
38+
git_config *cfg = NULL;
39+
int err = 0;
40+
2441
if (ftruncate(fd, 0) !=0 ) {
2542
abort();
2643
}
2744
if (lseek(fd, 0, SEEK_SET) != 0) {
2845
abort();
2946
}
30-
if (write(fd, data, size) != size) {
47+
if ((size_t)write(fd, data, size) != size) {
3148
abort();
3249
}
3350

34-
git_config *cfg;
35-
int err = git_config_open_ondisk(&cfg, path);
51+
err = git_config_open_ondisk(&cfg, path);
3652
if (err == 0) {
3753
git_config_foreach(cfg, foreach_cb, NULL);
3854
git_config_free(cfg);

0 commit comments

Comments
 (0)