Skip to content

Commit 1df0306

Browse files
committed
Sync with 2.12.5
Signed-off-by: Junio C Hamano <[email protected]>
2 parents 7234152 + 9752ad0 commit 1df0306

File tree

9 files changed

+155
-56
lines changed

9 files changed

+155
-56
lines changed

Documentation/RelNotes/2.10.5.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Git v2.10.5 Release Notes
2+
=========================
3+
4+
Fixes since v2.10.4
5+
-------------------
6+
7+
* "git cvsserver" no longer is invoked by "git daemon" by default,
8+
as it is old and largely unmaintained.
9+
10+
* Various Perl scripts did not use safe_pipe_capture() instead of
11+
backticks, leaving them susceptible to end-user input. They have
12+
been corrected.
13+
14+
Credits go to joernchen <[email protected]> for finding the
15+
unsafe constructs in "git cvsserver", and to Jeff King at GitHub for
16+
finding and fixing instances of the same issue in other scripts.
17+

Documentation/RelNotes/2.11.4.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Git v2.11.4 Release Notes
2+
=========================
3+
4+
Fixes since v2.11.3
5+
-------------------
6+
7+
* "git cvsserver" no longer is invoked by "git daemon" by default,
8+
as it is old and largely unmaintained.
9+
10+
* Various Perl scripts did not use safe_pipe_capture() instead of
11+
backticks, leaving them susceptible to end-user input. They have
12+
been corrected.
13+
14+
Credits go to joernchen <[email protected]> for finding the
15+
unsafe constructs in "git cvsserver", and to Jeff King at GitHub for
16+
finding and fixing instances of the same issue in other scripts.
17+

Documentation/RelNotes/2.12.5.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Git v2.12.5 Release Notes
2+
=========================
3+
4+
Fixes since v2.12.4
5+
-------------------
6+
7+
* "git cvsserver" no longer is invoked by "git daemon" by default,
8+
as it is old and largely unmaintained.
9+
10+
* Various Perl scripts did not use safe_pipe_capture() instead of
11+
backticks, leaving them susceptible to end-user input. They have
12+
been corrected.
13+
14+
Credits go to joernchen <[email protected]> for finding the
15+
unsafe constructs in "git cvsserver", and to Jeff King at GitHub for
16+
finding and fixing instances of the same issue in other scripts.
17+

Documentation/git-shell.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ EOF
7979
$ chmod +x $HOME/git-shell-commands/no-interactive-login
8080
----------------
8181

82+
To enable git-cvsserver access (which should generally have the
83+
`no-interactive-login` example above as a prerequisite, as creating
84+
the git-shell-commands directory allows interactive logins):
85+
86+
----------------
87+
$ cat >$HOME/git-shell-commands/cvs <<\EOF
88+
if ! test $# = 1 && test "$1" = "server"
89+
then
90+
echo >&2 "git-cvsserver only handles \"server\""
91+
exit 1
92+
fi
93+
exec git cvsserver server
94+
EOF
95+
$ chmod +x $HOME/git-shell-commands/cvs
96+
----------------
97+
8298
SEE ALSO
8399
--------
84100
ssh(1),

git-archimport.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ sub find_parents {
983983
# check that we actually know about the branch
984984
next unless -e "$git_dir/refs/heads/$branch";
985985

986-
my $mergebase = `git-merge-base $branch $ps->{branch}`;
986+
my $mergebase = safe_pipe_capture(qw(git-merge-base), $branch, $ps->{branch});
987987
if ($?) {
988988
# Don't die here, Arch supports one-way cherry-picking
989989
# between branches with no common base (or any relationship
@@ -1074,7 +1074,7 @@ sub find_parents {
10741074

10751075
sub git_rev_parse {
10761076
my $name = shift;
1077-
my $val = `git-rev-parse $name`;
1077+
my $val = safe_pipe_capture(qw(git-rev-parse), $name);
10781078
die "Error: git-rev-parse $name" if $?;
10791079
chomp $val;
10801080
return $val;

git-cvsimport.perl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ sub is_sha1 {
642642

643643
sub get_headref ($) {
644644
my $name = shift;
645+
$name =~ s/'/'\\''/;
645646
my $r = `git rev-parse --verify '$name' 2>/dev/null`;
646647
return undef unless $? == 0;
647648
chomp $r;

git-cvsserver.perl

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ sub req_Root
356356
return 0;
357357
}
358358

359-
my @gitvars = `git config -l`;
359+
my @gitvars = safe_pipe_capture(qw(git config -l));
360360
if ($?) {
361361
print "E problems executing git-config on the server -- this is not a git repository or the PATH is not set correctly.\n";
362362
print "E \n";
@@ -841,7 +841,7 @@ sub req_Modified
841841
# Save the file data in $state
842842
$state->{entries}{$state->{directory}.$data}{modified_filename} = $filename;
843843
$state->{entries}{$state->{directory}.$data}{modified_mode} = $mode;
844-
$state->{entries}{$state->{directory}.$data}{modified_hash} = `git hash-object $filename`;
844+
$state->{entries}{$state->{directory}.$data}{modified_hash} = safe_pipe_capture('git','hash-object',$filename);
845845
$state->{entries}{$state->{directory}.$data}{modified_hash} =~ s/\s.*$//s;
846846

847847
#$log->debug("req_Modified : file=$data mode=$mode size=$size");
@@ -943,7 +943,7 @@ sub req_co
943943

944944
# Provide list of modules, if -c was used.
945945
if (exists $state->{opt}{c}) {
946-
my $showref = `git show-ref --heads`;
946+
my $showref = safe_pipe_capture(qw(git show-ref --heads));
947947
for my $line (split '\n', $showref) {
948948
if ( $line =~ m% refs/heads/(.*)$% ) {
949949
print "M $1\t$1\n";
@@ -1181,7 +1181,7 @@ sub req_update
11811181
# projects (heads in this case) to checkout.
11821182
#
11831183
if ($state->{module} eq '') {
1184-
my $showref = `git show-ref --heads`;
1184+
my $showref = safe_pipe_capture(qw(git show-ref --heads));
11851185
print "E cvs update: Updating .\n";
11861186
for my $line (split '\n', $showref) {
11871187
if ( $line =~ m% refs/heads/(.*)$% ) {
@@ -1463,7 +1463,7 @@ sub req_update
14631463
# transmit file, format is single integer on a line by itself (file
14641464
# size) followed by the file contents
14651465
# TODO : we should copy files in blocks
1466-
my $data = `cat $mergedFile`;
1466+
my $data = safe_pipe_capture('cat', $mergedFile);
14671467
$log->debug("File size : " . length($data));
14681468
print length($data) . "\n";
14691469
print $data;
@@ -1579,7 +1579,7 @@ sub req_ci
15791579
$branchRef = "refs/heads/$stickyInfo->{tag}";
15801580
}
15811581

1582-
$parenthash = `git show-ref -s $branchRef`;
1582+
$parenthash = safe_pipe_capture('git', 'show-ref', '-s', $branchRef);
15831583
chomp $parenthash;
15841584
if ($parenthash !~ /^[0-9a-f]{40}$/)
15851585
{
@@ -1687,7 +1687,7 @@ sub req_ci
16871687
return;
16881688
}
16891689

1690-
my $treehash = `git write-tree`;
1690+
my $treehash = safe_pipe_capture(qw(git write-tree));
16911691
chomp $treehash;
16921692

16931693
$log->debug("Treehash : $treehash, Parenthash : $parenthash");
@@ -1704,7 +1704,7 @@ sub req_ci
17041704
}
17051705
close $msg_fh;
17061706

1707-
my $commithash = `git commit-tree $treehash -p $parenthash < $msg_filename`;
1707+
my $commithash = safe_pipe_capture('git', 'commit-tree', $treehash, '-p', $parenthash, '-F', $msg_filename);
17081708
chomp($commithash);
17091709
$log->info("Commit hash : $commithash");
17101710

@@ -2854,12 +2854,12 @@ sub transmitfile
28542854

28552855
die "Need filehash" unless ( defined ( $filehash ) and $filehash =~ /^[a-zA-Z0-9]{40}$/ );
28562856

2857-
my $type = `git cat-file -t $filehash`;
2857+
my $type = safe_pipe_capture('git', 'cat-file', '-t', $filehash);
28582858
chomp $type;
28592859

28602860
die ( "Invalid type '$type' (expected 'blob')" ) unless ( defined ( $type ) and $type eq "blob" );
28612861

2862-
my $size = `git cat-file -s $filehash`;
2862+
my $size = safe_pipe_capture('git', 'cat-file', '-s', $filehash);
28632863
chomp $size;
28642864

28652865
$log->debug("transmitfile($filehash) size=$size, type=$type");
@@ -3040,7 +3040,7 @@ sub ensureWorkTree
30403040
chdir $work->{emptyDir} or
30413041
die "Unable to chdir to $work->{emptyDir}\n";
30423042

3043-
my $ver = `git show-ref -s refs/heads/$state->{module}`;
3043+
my $ver = safe_pipe_capture('git', 'show-ref', '-s', "refs/heads/$state->{module}");
30443044
chomp $ver;
30453045
if ($ver !~ /^[0-9a-f]{40}$/)
30463046
{
@@ -3287,7 +3287,7 @@ sub open_blob_or_die
32873287
die "Need filehash\n";
32883288
}
32893289

3290-
my $type = `git cat-file -t $name`;
3290+
my $type = safe_pipe_capture('git', 'cat-file', '-t', $name);
32913291
chomp $type;
32923292

32933293
unless ( defined ( $type ) and $type eq "blob" )
@@ -3296,7 +3296,7 @@ sub open_blob_or_die
32963296
die ( "Invalid type '$type' (expected 'blob')" )
32973297
}
32983298

3299-
my $size = `git cat-file -s $name`;
3299+
my $size = safe_pipe_capture('git', 'cat-file', '-s', $name);
33003300
chomp $size;
33013301

33023302
$log->debug("open_blob_or_die($name) size=$size, type=$type");
@@ -3406,6 +3406,22 @@ sub refHashEqual
34063406
return $out;
34073407
}
34083408

3409+
# an alternative to `command` that allows input to be passed as an array
3410+
# to work around shell problems with weird characters in arguments
3411+
3412+
sub safe_pipe_capture {
3413+
3414+
my @output;
3415+
3416+
if (my $pid = open my $child, '-|') {
3417+
@output = (<$child>);
3418+
close $child or die join(' ',@_).": $! $?";
3419+
} else {
3420+
exec(@_) or die "$! $?"; # exec() can fail the executable can't be found
3421+
}
3422+
return wantarray ? @output : join('',@output);
3423+
}
3424+
34093425

34103426
package GITCVS::log;
34113427

@@ -3797,10 +3813,10 @@ sub update
37973813
# first lets get the commit list
37983814
$ENV{GIT_DIR} = $self->{git_path};
37993815

3800-
my $commitsha1 = `git rev-parse $self->{module}`;
3816+
my $commitsha1 = ::safe_pipe_capture('git', 'rev-parse', $self->{module});
38013817
chomp $commitsha1;
38023818

3803-
my $commitinfo = `git cat-file commit $self->{module} 2>&1`;
3819+
my $commitinfo = ::safe_pipe_capture('git', 'cat-file', 'commit', $self->{module});
38043820
unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ )
38053821
{
38063822
die("Invalid module '$self->{module}'");
@@ -3882,7 +3898,7 @@ sub update
38823898
# several candidate merge bases. let's assume
38833899
# that the first one is the best one.
38843900
my $base = eval {
3885-
safe_pipe_capture('git', 'merge-base',
3901+
::safe_pipe_capture('git', 'merge-base',
38863902
$lastpicked, $parent);
38873903
};
38883904
# The two branches may not be related at all,
@@ -4749,7 +4765,7 @@ sub getMetaFromCommithash
47494765
return $retVal;
47504766
}
47514767

4752-
my($fileHash)=safe_pipe_capture("git","rev-parse","$revCommit:$filename");
4768+
my($fileHash) = ::safe_pipe_capture("git","rev-parse","$revCommit:$filename");
47534769
chomp $fileHash;
47544770
if(!($fileHash=~/^[0-9a-f]{40}$/))
47554771
{
@@ -4844,8 +4860,8 @@ sub lookupCommitRef
48444860
return $commitHash;
48454861
}
48464862

4847-
$commitHash=safe_pipe_capture("git","rev-parse","--verify","--quiet",
4848-
$self->unescapeRefName($ref));
4863+
$commitHash = ::safe_pipe_capture("git","rev-parse","--verify","--quiet",
4864+
$self->unescapeRefName($ref));
48494865
$commitHash=~s/\s*$//;
48504866
if(!($commitHash=~/^[0-9a-f]{40}$/))
48514867
{
@@ -4854,7 +4870,7 @@ sub lookupCommitRef
48544870

48554871
if( defined($commitHash) )
48564872
{
4857-
my $type=safe_pipe_capture("git","cat-file","-t",$commitHash);
4873+
my $type = ::safe_pipe_capture("git","cat-file","-t",$commitHash);
48584874
if( ! ($type=~/^commit\s*$/ ) )
48594875
{
48604876
$commitHash=undef;
@@ -4907,7 +4923,7 @@ sub commitmessage
49074923
return $message;
49084924
}
49094925

4910-
my @lines = safe_pipe_capture("git", "cat-file", "commit", $commithash);
4926+
my @lines = ::safe_pipe_capture("git", "cat-file", "commit", $commithash);
49114927
shift @lines while ( $lines[0] =~ /\S/ );
49124928
$message = join("",@lines);
49134929
$message .= " " if ( $message =~ /\n$/ );
@@ -5056,25 +5072,6 @@ sub in_array
50565072
return $retval;
50575073
}
50585074

5059-
=head2 safe_pipe_capture
5060-
5061-
an alternative to `command` that allows input to be passed as an array
5062-
to work around shell problems with weird characters in arguments
5063-
5064-
=cut
5065-
sub safe_pipe_capture {
5066-
5067-
my @output;
5068-
5069-
if (my $pid = open my $child, '-|') {
5070-
@output = (<$child>);
5071-
close $child or die join(' ',@_).": $! $?";
5072-
} else {
5073-
exec(@_) or die "$! $?"; # exec() can fail the executable can't be found
5074-
}
5075-
return wantarray ? @output : join('',@output);
5076-
}
5077-
50785075
=head2 mangle_dirname
50795076
50805077
create a string from a directory name that is suitable to use as

shell.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@ static int do_generic_cmd(const char *me, char *arg)
2525
return execv_git_cmd(my_argv);
2626
}
2727

28-
static int do_cvs_cmd(const char *me, char *arg)
29-
{
30-
const char *cvsserver_argv[3] = {
31-
"cvsserver", "server", NULL
32-
};
33-
34-
if (!arg || strcmp(arg, "server"))
35-
die("git-cvsserver only handles server: %s", arg);
36-
37-
setup_path();
38-
return execv_git_cmd(cvsserver_argv);
39-
}
40-
4128
static int is_valid_cmd_name(const char *cmd)
4229
{
4330
/* Test command contains no . or / characters */
@@ -134,7 +121,6 @@ static struct commands {
134121
{ "git-receive-pack", do_generic_cmd },
135122
{ "git-upload-pack", do_generic_cmd },
136123
{ "git-upload-archive", do_generic_cmd },
137-
{ "cvs", do_cvs_cmd },
138124
{ NULL },
139125
};
140126

0 commit comments

Comments
 (0)