]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: Fix two 'uninitialized value' warnings in git_tree()
authorJakub Narebski <redacted>
Thu, 2 Oct 2008 14:50:04 +0000 (16:50 +0200)
committerLady <redacted>
Mon, 6 Apr 2026 04:07:34 +0000 (00:07 -0400)
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 <redacted>
Acked-by: Petr Baudis <redacted>
Signed-off-by: Shawn O. Pearce <redacted>
gitweb.perl

index cf4057a41f36eb4579f5bf76302486ebe7635a9afb9adc1c30ad936496bc16f3..e1aaefc683abe5af015b3059e98bc0c0cc49697736ac38d0993788d63f73f12e 100755 (executable)
@@ -4448,6 +4448,7 @@ sub git_tree {
                        $hash = $hash_base;
                }
        }
+       die_error(404, "No such tree") unless defined($hash);
        $/ = "\0";
        open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
                or die_error(500, "Open git-ls-tree failed");
@@ -4488,8 +4489,8 @@ sub git_tree {
                if ($basedir ne '' && substr($basedir, -1) ne '/') {
                        $basedir .= '/';
                }
+               git_print_page_path($file_name, 'tree', $hash_base);
        }
-       git_print_page_path($file_name, 'tree', $hash_base);
        print "<div class=\"page_body\">\n";
        print "<table class=\"tree\">\n";
        my $alternate = 1;
This page took 0.264464 seconds and 4 git commands to generate.