Unverified Commit dacac9e1 by Patrick Steinhardt Committed by GitHub

Merge pull request #5160 from pks-t/pks/win32-fuzzers

win32: fix fuzzers and have CI build them
parents a6ad9e8a eb27fb9b
...@@ -18,7 +18,7 @@ Write-Host "#################################################################### ...@@ -18,7 +18,7 @@ Write-Host "####################################################################
Write-Host "## Configuring build environment" Write-Host "## Configuring build environment"
Write-Host "##############################################################################" Write-Host "##############################################################################"
Invoke-Expression "cmake ${SourceDirectory} -DBUILD_EXAMPLES=ON -DENABLE_WERROR=ON ${Env:CMAKE_OPTIONS}" Invoke-Expression "cmake ${SourceDirectory} -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -DENABLE_WERROR=ON ${Env:CMAKE_OPTIONS}"
if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) } if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
Write-Host "" Write-Host ""
......
...@@ -7,15 +7,9 @@ ...@@ -7,15 +7,9 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#include <git2.h> #include "git2.h"
#include "config_backend.h" #include "config_backend.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int foreach_cb(const git_config_entry *entry, void *payload) int foreach_cb(const git_config_entry *entry, void *payload)
......
...@@ -7,14 +7,13 @@ ...@@ -7,14 +7,13 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#include <string.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "git2.h" #include "git2.h"
#include "git2/sys/transport.h" #include "git2/sys/transport.h"
#include "fileops.h"
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
...@@ -166,10 +165,23 @@ void fuzzer_git_abort(const char *op) ...@@ -166,10 +165,23 @@ void fuzzer_git_abort(const char *op)
int LLVMFuzzerInitialize(int *argc, char ***argv) int LLVMFuzzerInitialize(int *argc, char ***argv)
{ {
char tmp[] = "/tmp/git2.XXXXXX"; #if defined(_WIN32)
char tmpdir[MAX_PATH], path[MAX_PATH];
UNUSED(argc); if (GetTempPath((DWORD)sizeof(tmpdir), tmpdir) == 0)
UNUSED(argv); abort();
if (GetTempFileName(tmpdir, "lg2", 1, path) == 0)
abort();
if (git_futils_mkdir(path, 0700, 0) < 0)
abort();
#else
char path[] = "/tmp/git2.XXXXXX";
if (mkdtemp(path) != path)
abort();
#endif
if (git_libgit2_init() < 0) if (git_libgit2_init() < 0)
abort(); abort();
...@@ -177,10 +189,10 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) ...@@ -177,10 +189,10 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
if (git_libgit2_opts(GIT_OPT_SET_PACK_MAX_OBJECTS, 10000000) < 0) if (git_libgit2_opts(GIT_OPT_SET_PACK_MAX_OBJECTS, 10000000) < 0)
abort(); abort();
if (mkdtemp(tmp) != tmp) UNUSED(argc);
abort(); UNUSED(argv);
if (git_repository_init(&repo, tmp, 1) < 0) if (git_repository_init(&repo, path, 1) < 0)
fuzzer_git_abort("git_repository_init"); fuzzer_git_abort("git_repository_init");
return 0; return 0;
......
...@@ -7,16 +7,12 @@ ...@@ -7,16 +7,12 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include <unistd.h>
#include "git2.h" #include "git2.h"
#include "git2/sys/mempack.h" #include "git2/sys/mempack.h"
#include "common.h"
#define UNUSED(x) (void)(x) #include "buffer.h"
static git_odb *odb = NULL; static git_odb *odb = NULL;
static git_odb_backend *mempack = NULL; static git_odb_backend *mempack = NULL;
...@@ -27,8 +23,9 @@ static const unsigned int base_obj_len = 2; ...@@ -27,8 +23,9 @@ static const unsigned int base_obj_len = 2;
int LLVMFuzzerInitialize(int *argc, char ***argv) int LLVMFuzzerInitialize(int *argc, char ***argv)
{ {
UNUSED(argc); GIT_UNUSED(argc);
UNUSED(argv); GIT_UNUSED(argv);
if (git_libgit2_init() < 0) { if (git_libgit2_init() < 0) {
fprintf(stderr, "Failed to initialize libgit2\n"); fprintf(stderr, "Failed to initialize libgit2\n");
abort(); abort();
...@@ -54,12 +51,11 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) ...@@ -54,12 +51,11 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{ {
git_indexer *indexer = NULL;
git_indexer_progress stats = {0, 0}; git_indexer_progress stats = {0, 0};
git_indexer *indexer = NULL;
git_buf path = GIT_BUF_INIT;
git_oid oid;
bool append_hash = false; bool append_hash = false;
git_oid id;
char hash[GIT_OID_HEXSZ + 1] = {0};
char path[PATH_MAX];
if (size == 0) if (size == 0)
return 0; return 0;
...@@ -70,7 +66,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -70,7 +66,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
git_mempack_reset(mempack); git_mempack_reset(mempack);
if (git_odb_write(&id, odb, base_obj, base_obj_len, GIT_OBJECT_BLOB) < 0) { if (git_odb_write(&oid, odb, base_obj, base_obj_len, GIT_OBJECT_BLOB) < 0) {
fprintf(stderr, "Failed to add an object to the odb\n"); fprintf(stderr, "Failed to add an object to the odb\n");
abort(); abort();
} }
...@@ -92,7 +88,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -92,7 +88,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (git_indexer_append(indexer, data, size, &stats) < 0) if (git_indexer_append(indexer, data, size, &stats) < 0)
goto cleanup; goto cleanup;
if (append_hash) { if (append_hash) {
git_oid oid;
if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB) < 0) { if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n"); fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort(); abort();
...@@ -104,19 +99,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -104,19 +99,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (git_indexer_commit(indexer, &stats) < 0) if (git_indexer_commit(indexer, &stats) < 0)
goto cleanup; goto cleanup;
/* if (git_buf_printf(&path, "pack-%s.idx", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
* We made it! We managed to produce a valid packfile. goto cleanup;
* Let's clean it up. p_unlink(git_buf_cstr(&path));
*/
git_oid_fmt(hash, git_indexer_hash(indexer)); git_buf_clear(&path);
printf("Generated packfile %s\n", hash);
snprintf(path, sizeof(path), "pack-%s.idx", hash); if (git_buf_printf(&path, "pack-%s.pack", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
unlink(path); goto cleanup;
snprintf(path, sizeof(path), "pack-%s.pack", hash); p_unlink(git_buf_cstr(&path));
unlink(path);
cleanup: cleanup:
git_mempack_reset(mempack); git_mempack_reset(mempack);
git_indexer_free(indexer); git_indexer_free(indexer);
git_buf_dispose(&path);
return 0; return 0;
} }
...@@ -5,11 +5,7 @@ ...@@ -5,11 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#include <assert.h>
#include <dirent.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "git2.h" #include "git2.h"
#include "fileops.h" #include "fileops.h"
...@@ -24,7 +20,7 @@ static int run_one_file(const char *filename) ...@@ -24,7 +20,7 @@ static int run_one_file(const char *filename)
int error = 0; int error = 0;
if (git_futils_readbuffer(&buf, filename) < 0) { if (git_futils_readbuffer(&buf, filename) < 0) {
fprintf(stderr, "Failed to read %s: %m\n", filename); fprintf(stderr, "Failed to read %s: %s\n", filename, git_error_last()->message);
error = -1; error = -1;
goto exit; goto exit;
} }
...@@ -57,7 +53,8 @@ int main(int argc, char **argv) ...@@ -57,7 +53,8 @@ int main(int argc, char **argv)
LLVMFuzzerInitialize(&argc, &argv); LLVMFuzzerInitialize(&argc, &argv);
if (git_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) { if (git_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) {
fprintf(stderr, "Failed to scan corpus directory: %m\n"); fprintf(stderr, "Failed to scan corpus directory '%s': %s\n",
argv[1], git_error_last()->message);
error = -1; error = -1;
goto exit; goto exit;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment