From: Mark Rada Date: Sat, 26 Sep 2009 17:46:08 +0000 (-0400) Subject: gitweb: check given hash before trying to create snapshot X-Git-Url: https://git.ladys.computer/Gitweb/commitdiff_plain/ed433e486ee9aa30b6685a586a09ac0a32dcf98d879ccc9ced5ed2eb6a52422f?hp=4a7fb0bc24b3a9ff745a1faae8d8df828563cf61e603d9cffbfdbb5641844581 gitweb: check given hash before trying to create snapshot Makes things nicer in cases when you hand craft the snapshot URL but make a typo in defining the hash variable (e.g. netx instead of next); you will now get an error message instead of a broken tarball. Tests for t9501 are included to demonstrate added functionality. Signed-off-by: Mark Rada Signed-off-by: Shawn O. Pearce --- diff --git a/gitweb.perl b/gitweb.perl index 03900fa..7e1e27a 100755 --- a/gitweb.perl +++ b/gitweb.perl @@ -5375,8 +5375,11 @@ sub git_snapshot { die_error(403, "Unsupported snapshot format"); } - if (!defined $hash) { - $hash = git_get_head_hash($project); + my $type = git_get_type("$hash^{}"); + if (!$type) { + die_error(404, 'Object does not exist'); + } elsif ($type eq 'blob') { + die_error(400, 'Object is not a tree-ish'); } my $name = $project;