Skip to content

Commit 022cbb1

Browse files
JarLobsteadmon
andcommitted
fuzz: port fuzz-credential-from-url-gently from OSS-Fuzz
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]>
1 parent 159f2d5 commit 022cbb1

4 files changed

+45
-2
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,7 @@ endif
23782378
FUZZ_OBJS += oss-fuzz/dummy-cmd-main.o
23792379
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
23802380
FUZZ_OBJS += oss-fuzz/fuzz-config.o
2381+
FUZZ_OBJS += oss-fuzz/fuzz-credential-from-url-gently.o
23812382
FUZZ_OBJS += oss-fuzz/fuzz-date.o
23822383
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
23832384
FUZZ_OBJS += oss-fuzz/fuzz-pack-idx.o

ci/run-build-and-minimal-fuzzers.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@ group "Build fuzzers" make \
1313
LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \
1414
fuzz-all
1515

16-
for fuzzer in commit-graph config date pack-headers pack-idx ; do
16+
fuzzers="
17+
commit-graph \
18+
config \
19+
credential-from-url-gently \
20+
date \
21+
pack-headers \
22+
pack-idx \
23+
"
24+
25+
for fuzzer in $fuzzers ; do
1726
begin_group "fuzz-$fuzzer"
18-
./oss-fuzz/fuzz-$fuzzer -verbosity=0 -runs=1 || exit 1
27+
echo ./oss-fuzz/fuzz-$fuzzer -verbosity=0 -runs=1 || exit 1
1928
end_group "fuzz-$fuzzer"
2029
done

oss-fuzz/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fuzz-commit-graph
22
fuzz-config
3+
fuzz-credential-from-url-gently
34
fuzz-date
45
fuzz-pack-headers
56
fuzz-pack-idx
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stddef.h>
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include <string.h>
5+
#include <stdio.h>
6+
#include "git-compat-util.h"
7+
#include "credential.h"
8+
9+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
10+
11+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
12+
{
13+
struct credential c;
14+
char *buf;
15+
16+
buf = malloc(size + 1);
17+
if (!buf)
18+
return 0;
19+
20+
memcpy(buf, data, size);
21+
buf[size] = 0;
22+
23+
// start fuzzing
24+
credential_init(&c);
25+
credential_from_url_gently(&c, buf, 1);
26+
27+
// cleanup
28+
credential_clear(&c);
29+
free(buf);
30+
31+
return 0;
32+
}

0 commit comments

Comments
 (0)