Skip to content

Commit 6798b08

Browse files
avargitster
authored andcommitted
perl Git.pm: don't ignore signalled failure in _cmd_close()
Fix misbehavior in Git.pm that dates back to the very first version of the library in git.git added in b1edc53 (Introduce Git.pm (v4), 2006-06-24). When we fail to execute a command we shouldn't ignore all signals, those can happen e.g. if abort() is called, or if the command segfaults. Because of this we'd consider e.g. a command that died due to LSAN exiting with abort() successful, as is the case with the tests listed as running successfully with SANITIZE=leak in 9081a42 (checkout: fix "branch info" memory leaks, 2021-11-16). We did run them successfully, but only because we ignored these errors. This was then made worse by the use of "abort_on_error=1" for LSAN added in 85b81b3 (test-lib: set LSAN_OPTIONS to abort by default, 2017-09-05). Doing that makes sense, but without providing that option we'd have a "$? >> 8" of "23" on failure, with abort_on_error=1 we'll get "0". All of our tests pass even without the SIGPIPE exception being added here, but as the code appears to have been trying to ignore it let's keep ignoring it for now. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c53a8c commit 6798b08

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

perl/Git.pm

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,16 @@ sub _setup_git_cmd_env {
16861686
# by searching for it at proper places.
16871687
sub _execv_git_cmd { exec('git', @_); }
16881688

1689+
sub _is_sig {
1690+
my ($v, $n) = @_;
1691+
1692+
# We are avoiding a "use POSIX qw(SIGPIPE SIGABRT)" in the hot
1693+
# Git.pm codepath.
1694+
require POSIX;
1695+
no strict 'refs';
1696+
$v == *{"POSIX::$n"}->();
1697+
}
1698+
16891699
# Close pipe to a subprocess.
16901700
sub _cmd_close {
16911701
my $ctx = shift @_;
@@ -1698,9 +1708,16 @@ sub _cmd_close {
16981708
} elsif ($? >> 8) {
16991709
# The caller should pepper this.
17001710
throw Git::Error::Command($ctx, $? >> 8);
1711+
} elsif ($? & 127 && _is_sig($? & 127, "SIGPIPE")) {
1712+
# we might e.g. closed a live stream; the command
1713+
# dying of SIGPIPE would drive us here.
1714+
} elsif ($? & 127 && _is_sig($? & 127, "SIGABRT")) {
1715+
die sprintf('BUG?: got SIGABRT ($? = %d, $? & 127 = %d) when closing pipe',
1716+
$?, $? & 127);
1717+
} elsif ($? & 127) {
1718+
die sprintf('got signal ($? = %d, $? & 127 = %d) when closing pipe',
1719+
$?, $? & 127);
17011720
}
1702-
# else we might e.g. closed a live stream; the command
1703-
# dying of SIGPIPE would drive us here.
17041721
}
17051722
}
17061723

t/t9102-git-svn-deep-rmdir.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/sh
22
test_description='git svn rmdir'
33

4-
TEST_PASSES_SANITIZE_LEAK=true
54
. ./lib-git-svn.sh
65

76
test_expect_success 'initialize repo' '

t/t9123-git-svn-rebuild-with-rewriteroot.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
test_description='git svn respects rewriteRoot during rebuild'
77

8-
TEST_PASSES_SANITIZE_LEAK=true
98
. ./lib-git-svn.sh
109

1110
mkdir import

t/t9128-git-svn-cmd-branch.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
test_description='git svn partial-rebuild tests'
77

8-
TEST_PASSES_SANITIZE_LEAK=true
98
. ./lib-git-svn.sh
109

1110
test_expect_success 'initialize svnrepo' '

t/t9167-git-svn-cmd-branch-subproject.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
test_description='git svn branch for subproject clones'
77

8-
TEST_PASSES_SANITIZE_LEAK=true
98
. ./lib-git-svn.sh
109

1110
test_expect_success 'initialize svnrepo' '

0 commit comments

Comments
 (0)