Skip to content

Commit

Permalink
fuzz: port fuzz-credential-from-url-gently from OSS-Fuzz
Browse files Browse the repository at this point in the history
Git's fuzz tests are run continuously as part of OSS-Fuzz [1]. Several
additional fuzz tests have been contributed directly to OSS-Fuzz;
however, these tests are vulnerable to bitrot because they are not built
during Git's CI runs, and thus breaking changes are much less likely to
be noticed by Git contributors.

Port one of these tests back to the Git project:
fuzz-credential-from-url-gently

This test was originally contributed to the OSS-Fuzz repo in commit
c58ac4492 (Git fuzzing: uncomment the existing and add new targets.
(#11486), 2024-02-21).

[1] https://github.com/google/oss-fuzz

Co-authored-by: Josh Steadmon <[email protected]>
Change-Id: I1068cb719d2bee174c3fda141846838469db6e7c
Signed-off-by: Josh Steadmon <[email protected]>
  • Loading branch information
JarLob and steadmon committed Aug 29, 2024
1 parent 159f2d5 commit 7984d3a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,7 @@ endif
FUZZ_OBJS += oss-fuzz/dummy-cmd-main.o
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
FUZZ_OBJS += oss-fuzz/fuzz-config.o
FUZZ_OBJS += oss-fuzz/fuzz-credential-from-url-gently.o
FUZZ_OBJS += oss-fuzz/fuzz-date.o
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
FUZZ_OBJS += oss-fuzz/fuzz-pack-idx.o
Expand Down
13 changes: 11 additions & 2 deletions ci/run-build-and-minimal-fuzzers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ group "Build fuzzers" make \
LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \
fuzz-all

for fuzzer in commit-graph config date pack-headers pack-idx ; do
fuzzers="
commit-graph \
config \
credential-from-url-gently \
date \
pack-headers \
pack-idx \
"

for fuzzer in $fuzzers ; do
begin_group "fuzz-$fuzzer"
./oss-fuzz/fuzz-$fuzzer -verbosity=0 -runs=1 || exit 1
echo ./oss-fuzz/fuzz-$fuzzer -verbosity=0 -runs=1 || exit 1
end_group "fuzz-$fuzzer"
done
1 change: 1 addition & 0 deletions oss-fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fuzz-commit-graph
fuzz-config
fuzz-credential-from-url-gently
fuzz-date
fuzz-pack-headers
fuzz-pack-idx
32 changes: 32 additions & 0 deletions oss-fuzz/fuzz-credential-from-url-gently.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "git-compat-util.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "credential.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
struct credential c;
char *buf;

buf = malloc(size + 1);
if (!buf)
return 0;

memcpy(buf, data, size);
buf[size] = 0;

// start fuzzing
credential_init(&c);
credential_from_url_gently(&c, buf, 1);

// cleanup
credential_clear(&c);
free(buf);

return 0;
}

0 comments on commit 7984d3a

Please sign in to comment.