Skip to content

Commit f02e234

Browse files
committed
Merge branch 'ab/valgrind-fixes' into maint
A bit of test framework fixes with a few fixes to issues found by valgrind. source: <[email protected]> * ab/valgrind-fixes: commit-graph.c: don't assume that stat() succeeds object-file: fix a unpack_loose_header() regression in 3b6a8db log test: skip a failing mkstemp() test under valgrind tests: using custom GIT_EXEC_PATH breaks --valgrind tests
2 parents 9d13041 + 7c89855 commit f02e234

File tree

7 files changed

+39
-14
lines changed

7 files changed

+39
-14
lines changed

commit-graph.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,8 @@ static void mark_commit_graphs(struct write_commit_graph_context *ctx)
22062206
struct stat st;
22072207
struct utimbuf updated_time;
22082208

2209-
stat(ctx->commit_graph_filenames_before[i], &st);
2209+
if (stat(ctx->commit_graph_filenames_before[i], &st) < 0)
2210+
continue;
22102211

22112212
updated_time.actime = st.st_atime;
22122213
updated_time.modtime = now;
@@ -2247,7 +2248,8 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
22472248
strbuf_setlen(&path, dirnamelen);
22482249
strbuf_addstr(&path, de->d_name);
22492250

2250-
stat(path.buf, &st);
2251+
if (stat(path.buf, &st) < 0)
2252+
continue;
22512253

22522254
if (st.st_mtime > expire_time)
22532255
continue;

object-file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,8 +2623,12 @@ int read_loose_object(const char *path,
26232623
goto out;
26242624
}
26252625

2626-
if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
2627-
NULL) < 0) {
2626+
switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
2627+
NULL)) {
2628+
case ULHR_OK:
2629+
break;
2630+
case ULHR_BAD:
2631+
case ULHR_TOO_LONG:
26282632
error(_("unable to unpack header of %s"), path);
26292633
goto out;
26302634
}

t/t0060-path-utils.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,15 @@ test_lazy_prereq CAN_EXEC_IN_PWD '
542542
./git rev-parse
543543
'
544544

545-
test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' '
545+
test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' '
546546
mkdir -p pretend/bin pretend/libexec/git-core &&
547547
echo "echo HERE" | write_script pretend/libexec/git-core/git-here &&
548548
cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
549549
GIT_EXEC_PATH= ./pretend/bin/git here >actual &&
550550
echo HERE >expect &&
551551
test_cmp expect actual'
552552

553-
test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' '
553+
test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' '
554554
mkdir -p pretend/bin &&
555555
cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
556556
git config yes.path "%(prefix)/yes" &&

t/t1006-cat-file.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' '
681681
682682
# Setup and create the empty blob and its path
683683
empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) &&
684-
git hash-object -w --stdin </dev/null &&
684+
empty_blob=$(git hash-object -w --stdin </dev/null) &&
685685
686686
# Create another blob and its path
687687
echo other >other.blob &&
@@ -722,7 +722,13 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' '
722722
# content out as-is. Try to make it zlib-invalid.
723723
mv -f other.blob "$empty_path" &&
724724
test_must_fail git fsck 2>err.fsck &&
725-
grep "^error: inflate: data stream error (" err.fsck
725+
cat >expect <<-EOF &&
726+
error: inflate: data stream error (incorrect header check)
727+
error: unable to unpack header of ./$empty_path
728+
error: $empty_blob: object corrupt or missing: ./$empty_path
729+
EOF
730+
grep "^error: " err.fsck >actual &&
731+
test_cmp expect actual
726732
)
727733
'
728734

t/t1450-fsck.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,19 @@ test_expect_success 'fsck finds problems in duplicate loose objects' '
774774
# no "-d" here, so we end up with duplicates
775775
git repack &&
776776
# now corrupt the loose copy
777-
file=$(sha1_file "$(git rev-parse HEAD)") &&
777+
oid="$(git rev-parse HEAD)" &&
778+
file=$(sha1_file "$oid") &&
778779
rm "$file" &&
779780
echo broken >"$file" &&
780-
test_must_fail git fsck
781+
test_must_fail git fsck 2>err &&
782+
783+
cat >expect <<-EOF &&
784+
error: inflate: data stream error (incorrect header check)
785+
error: unable to unpack header of $file
786+
error: $oid: object corrupt or missing: $file
787+
EOF
788+
grep "^error: " err >actual &&
789+
test_cmp expect actual
781790
)
782791
'
783792

t/t4202-log.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,10 +1992,13 @@ test_expect_success GPG 'log --show-signature for merged tag with GPG failure' '
19921992
git tag -s -m signed_tag_msg signed_tag_fail &&
19931993
git checkout plain-fail &&
19941994
git merge --no-ff -m msg signed_tag_fail &&
1995-
TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual &&
1996-
grep "^merged tag" actual &&
1997-
grep "^No signature" actual &&
1998-
! grep "^gpg: Signature made" actual
1995+
if ! test_have_prereq VALGRIND
1996+
then
1997+
TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual &&
1998+
grep "^merged tag" actual &&
1999+
grep "^No signature" actual &&
2000+
! grep "^gpg: Signature made" actual
2001+
fi
19992002
'
20002003

20012004
test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' '

t/test-lib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,7 @@ test -n "$USE_LIBPCRE2" && test_set_prereq PCRE
16661666
test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
16671667
test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
16681668
test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK
1669+
test -n "$GIT_VALGRIND_ENABLED" && test_set_prereq VALGRIND
16691670

16701671
if test -z "$GIT_TEST_CHECK_CACHE_TREE"
16711672
then

0 commit comments

Comments
 (0)