@matheusbsbs / matheus-bagliano / commits / 198a2a8a69
Fork 0

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 <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed May 12, 2007 at 21:16 UTC 198a2a8a69921327513c32512bdac77f52ab95d3
1 file changed +15 -1
gitweb/gitweb.perl
+15 -1
@@ -1060,6 +1060,11 @@ sub git_get_hash_by_path {
1060 my $line = <$fd>;
1061 close $fd or return undef;
1062
1063 + if (!defined $line) {
1064 + # there is no tree or hash given by $path at $base
1065 + return undef;
1066 + }
1067 +
1068 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1069 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1070 if (defined $type && $type ne $2) {
@@ -1376,8 +1381,12 @@ sub parse_commit_text {
1381
1382 pop @commit_lines; # Remove '\0'
1383
1384 + if (! @commit_lines) {
1385 + return;
1386 + }
1387 +
1388 my $header = shift @commit_lines;
1380 - if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1389 + if ($header !~ m/^[0-9a-fA-F]{40}/) {
1390 return;
1391 }
1392 ($co{'id'}, my @parents) = split ' ', $header;
@@ -3409,6 +3418,11 @@ sub git_tag {
3418 git_header_html();
3419 git_print_page_nav('','', $head,undef,$head);
3420 my %tag = parse_tag($hash);
3421 +
3422 + if (! %tag) {
3423 + die_error(undef, "Unknown tag object");
3424 + }
3425 +
3426 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
3427 print "<div class=\"title_text\">\n" .
3428 "<table cellspacing=\"0\">\n" .