Skip to content

Commit a6b2fff

Browse files
committed
fuzzers: use POSIX emulation layer to unlink files
Use `p_unlink` instead of `unlink` to remove the generated packfiles in our packfile fuzzer. Like this, we do not have to worry about using proper includes that are known on all platforms, especially Win32.
1 parent 6905581 commit a6b2fff

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

fuzzers/packfile_fuzzer.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
#include "git2.h"
1717
#include "git2/sys/mempack.h"
18-
19-
#define UNUSED(x) (void)(x)
18+
#include "common.h"
2019

2120
static git_odb *odb = NULL;
2221
static git_odb_backend *mempack = NULL;
@@ -27,8 +26,9 @@ static const unsigned int base_obj_len = 2;
2726

2827
int LLVMFuzzerInitialize(int *argc, char ***argv)
2928
{
30-
UNUSED(argc);
31-
UNUSED(argv);
29+
GIT_UNUSED(argc);
30+
GIT_UNUSED(argv);
31+
3232
if (git_libgit2_init() < 0) {
3333
fprintf(stderr, "Failed to initialize libgit2\n");
3434
abort();
@@ -59,7 +59,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
5959
bool append_hash = false;
6060
git_oid id;
6161
char hash[GIT_OID_HEXSZ + 1] = {0};
62-
char path[PATH_MAX];
62+
char path[GIT_PATH_MAX];
6363

6464
if (size == 0)
6565
return 0;
@@ -111,9 +111,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
111111
git_oid_fmt(hash, git_indexer_hash(indexer));
112112
printf("Generated packfile %s\n", hash);
113113
snprintf(path, sizeof(path), "pack-%s.idx", hash);
114-
unlink(path);
114+
p_unlink(path);
115115
snprintf(path, sizeof(path), "pack-%s.pack", hash);
116-
unlink(path);
116+
p_unlink(path);
117117

118118
cleanup:
119119
git_mempack_reset(mempack);

0 commit comments

Comments
 (0)