Skip to content

Commit 198a2a8

Browse files
jnarebJunio C Hamano
authored andcommitted
gitweb: Check if requested object exists
Try to avoid "Use of uninitialized value ..." errors caused by bad revision, incorrect filename, wrong object id, bad file etc. (wrong value of 'h', 'hb', 'f', etc. parameters). This avoids polluting web server errors log. Correct git_get_hash_by_path and parse_commit_text (and, in turn, parse_commit) to return undef if object does not exist. Check in git_tag if requested tag exists. Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2983cb commit 198a2a8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

gitweb/gitweb.perl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,11 @@ sub git_get_hash_by_path {
10601060
my $line = <$fd>;
10611061
close $fd or return undef;
10621062

1063+
if (!defined $line) {
1064+
# there is no tree or hash given by $path at $base
1065+
return undef;
1066+
}
1067+
10631068
#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
10641069
$line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
10651070
if (defined $type && $type ne $2) {
@@ -1376,8 +1381,12 @@ sub parse_commit_text {
13761381

13771382
pop @commit_lines; # Remove '\0'
13781383

1384+
if (! @commit_lines) {
1385+
return;
1386+
}
1387+
13791388
my $header = shift @commit_lines;
1380-
if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1389+
if ($header !~ m/^[0-9a-fA-F]{40}/) {
13811390
return;
13821391
}
13831392
($co{'id'}, my @parents) = split ' ', $header;
@@ -3409,6 +3418,11 @@ sub git_tag {
34093418
git_header_html();
34103419
git_print_page_nav('','', $head,undef,$head);
34113420
my %tag = parse_tag($hash);
3421+
3422+
if (! %tag) {
3423+
die_error(undef, "Unknown tag object");
3424+
}
3425+
34123426
git_print_header_div('commit', esc_html($tag{'name'}), $hash);
34133427
print "<div class=\"title_text\">\n" .
34143428
"<table cellspacing=\"0\">\n" .

0 commit comments

Comments
 (0)