gitweb: Secure against commit-ish/tree-ish with the same name as path
Add "--" after <commit-ish> or <tree-ish> argument to clearly mark it as <commit-ish> or <tree-ish> and not pathspec, securing against refs with the same names as files or directories in [live] repository. Some wrapping to reduce line length as well. [jc: with "oops, ls-tree does not want --" fix-up manually applied.] Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Oct 30, 2006 at 22:29 UTC
45bd0c808d2a89254ee50807a99b7cf1147aa6d7
1 file changed
+22
-14
gitweb/gitweb.perl
+22
-14
@@ -1111,7 +1111,9 @@ sub parse_commit {
1111
@commit_lines = @$commit_text;
1112
} else {
1113
local $/ = "\0";
1114
- open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1114
+ open my $fd, "-|", git_cmd(), "rev-list",
1115
+ "--header", "--parents", "--max-count=1",
1116
+ $commit_id, "--"
1117
or return;
1118
@commit_lines = split '\n', <$fd>;
1119
close $fd or return;
@@ -2529,7 +2531,7 @@ sub git_summary {
2531
}
2532
2533
open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
2532
- git_get_head_hash($project)
2534
+ git_get_head_hash($project), "--"
2535
or die_error(undef, "Open git-rev-list failed");
2536
my @revlist = map { chomp; $_ } <$fd>;
2537
close $fd;
@@ -3072,7 +3074,7 @@ sub git_log {
3074
my $refs = git_get_references();
3075
3076
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3075
- open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
3077
+ open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash, "--"
3078
or die_error(undef, "Open git-rev-list failed");
3079
my @revlist = map { chomp; $_ } <$fd>;
3080
close $fd;
@@ -3130,7 +3132,7 @@ sub git_commit {
3132
$parent = "--root";
3133
}
3134
open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
3133
- @diff_opts, $parent, $hash
3135
+ @diff_opts, $parent, $hash, "--"
3136
or die_error(undef, "Open git-diff-tree failed");
3137
my @difftree = map { chomp; $_ } <$fd>;
3138
close $fd or die_error(undef, "Reading git-diff-tree failed");
@@ -3235,7 +3237,8 @@ sub git_blobdiff {
3237
if (defined $hash_base && defined $hash_parent_base) {
3238
if (defined $file_name) {
3239
# read raw output
3238
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3240
+ open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3241
+ $hash_parent_base, $hash_base,
3242
"--", $file_name
3243
or die_error(undef, "Open git-diff-tree failed");
3244
@difftree = map { chomp; $_ } <$fd>;
@@ -3249,7 +3252,8 @@ sub git_blobdiff {
3252
# try to find filename from $hash
3253
3254
# read filtered raw output
3252
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3255
+ open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3256
+ $hash_parent_base, $hash_base, "--"
3257
or die_error(undef, "Open git-diff-tree failed");
3258
@difftree =
3259
# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
@@ -3319,7 +3323,8 @@ sub git_blobdiff {
3323
}
3324
3325
# open patch output
3322
- open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
3326
+ open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts,
3327
+ $hash_parent, $hash, "--"
3328
or die_error(undef, "Open git-diff failed");
3329
} else {
3330
die_error('404 Not Found', "Missing one of the blob diff parameters")
@@ -3450,8 +3455,8 @@ sub git_commitdiff {
3455
my @difftree;
3456
if ($format eq 'html') {
3457
open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3453
- "--no-commit-id",
3454
- "--patch-with-raw", "--full-index", $hash_parent, $hash
3458
+ "--no-commit-id", "--patch-with-raw", "--full-index",
3459
+ $hash_parent, $hash, "--"
3460
or die_error(undef, "Open git-diff-tree failed");
3461
3462
while (chomp(my $line = <$fd>)) {
@@ -3462,7 +3467,7 @@ sub git_commitdiff {
3467
3468
} elsif ($format eq 'plain') {
3469
open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3465
- '-p', $hash_parent, $hash
3470
+ '-p', $hash_parent, $hash, "--"
3471
or die_error(undef, "Open git-diff-tree failed");
3472
3473
} else {
@@ -3639,7 +3644,9 @@ sub git_search {
3644
my $alternate = 1;
3645
if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3646
$/ = "\0";
3642
- open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
3647
+ open my $fd, "-|", git_cmd(), "rev-list",
3648
+ "--header", "--parents", $hash, "--"
3649
+ or next;
3650
while (my $commit_text = <$fd>) {
3651
if (!grep m/$searchtext/i, $commit_text) {
3652
next;
@@ -3785,7 +3792,7 @@ sub git_shortlog {
3792
my $refs = git_get_references();
3793
3794
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3788
- open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
3795
+ open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash, "--"
3796
or die_error(undef, "Open git-rev-list failed");
3797
my @revlist = map { chomp; $_ } <$fd>;
3798
close $fd;
@@ -3813,7 +3820,8 @@ sub git_shortlog {
3820
3821
sub git_rss {
3822
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3816
- open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
3823
+ open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150",
3824
+ git_get_head_hash($project), "--"
3825
or die_error(undef, "Open git-rev-list failed");
3826
my @revlist = map { chomp; $_ } <$fd>;
3827
close $fd or die_error(undef, "Reading git-rev-list failed");
@@ -3837,7 +3845,7 @@ XML
3845
}
3846
my %cd = parse_date($co{'committer_epoch'});
3847
open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
3840
- $co{'parent'}, $co{'id'}
3848
+ $co{'parent'}, $co{'id'}, "--"
3849
or next;
3850
my @difftree = map { chomp; $_ } <$fd>;
3851
close $fd