Skip to content

Commit 27dd738

Browse files
joernchengitster
authored andcommitted
cvsserver: use safe_pipe_capture instead of backticks
This makes the script pass arguments that are derived from end-user input in safer way when invoking subcommands. Reported-by: joernchen <[email protected]> Signed-off-by: joernchen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fce13af commit 27dd738

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

git-cvsserver.perl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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");
@@ -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
{
@@ -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");
@@ -3813,10 +3813,10 @@ sub update
38133813
# first lets get the commit list
38143814
$ENV{GIT_DIR} = $self->{git_path};
38153815

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

3819-
my $commitinfo = `git cat-file commit $self->{module} 2>&1`;
3819+
my $commitinfo = ::safe_pipe_capture('git', 'cat-file', 'commit', $self->{module});
38203820
unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ )
38213821
{
38223822
die("Invalid module '$self->{module}'");

0 commit comments

Comments
 (0)