Skip to content

Commit 2d7a353

Browse files
jnarebspearce
authored andcommitted
gitweb: Fix two 'uninitialized value' warnings in git_tree()
If we did try to access nonexistent directory or file, which means that git_get_hash_by_path() returns `undef`, uninitialized $hash variable was passed to 'open' call. Now we fail early with "404 Not Found - No such tree" error. (If we try to access something which does not resolve to tree-ish, for example a file / 'blob' object, the error will be caught later, as "404 Not Found - Reading tree failed" error). If we tried to use 'tree' action without $file_name ('f' parameter) set, which means either tree given by hash or a top tree (and we currently cannot distinguish between those two cases), we cannot print path breadcrumbs with git_print_page_path(). Fix this by moving call to git_print_page_path() inside conditional. Signed-off-by: Jakub Narebski <[email protected]> Acked-by: Petr Baudis <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 6e2dfb1 commit 2d7a353

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

gitweb/gitweb.perl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4421,6 +4421,7 @@ sub git_tree {
44214421
$hash = $hash_base;
44224422
}
44234423
}
4424+
die_error(404, "No such tree") unless defined($hash);
44244425
$/ = "\0";
44254426
open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
44264427
or die_error(500, "Open git-ls-tree failed");
@@ -4461,8 +4462,8 @@ sub git_tree {
44614462
if ($basedir ne '' && substr($basedir, -1) ne '/') {
44624463
$basedir .= '/';
44634464
}
4465+
git_print_page_path($file_name, 'tree', $hash_base);
44644466
}
4465-
git_print_page_path($file_name, 'tree', $hash_base);
44664467
print "<div class=\"page_body\">\n";
44674468
print "<table class=\"tree\">\n";
44684469
my $alternate = 1;

0 commit comments

Comments
 (0)