From: Kay Sievers Date: Sun, 7 Aug 2005 18:15:44 +0000 (+0200) Subject: v055 X-Git-Tag: v1.4.0~1^2~116 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a59d4afd69e497193ac63c8633431f9b32211b4d;p=git.git v055 --- diff --git a/gitweb.cgi b/gitweb.cgi index 017664b8f..8c46a3a04 100755 --- a/gitweb.cgi +++ b/gitweb.cgi @@ -14,42 +14,45 @@ use CGI::Carp qw(fatalsToBrowser); my $cgi = new CGI; -my $version = "053"; -my $projectroot = "/pub/scm"; +my $version = "055"; +my $projectroot = "/home/kay/public_html/pub/scm"; my $defaultprojects = "linux/kernel/git"; -my $gitbin = "/usr/bin"; -my $gittmp = "/tmp/gitweb"; -my $giturl = "/pub/software/scm/cogito"; +my $gitbin = "/home/kay/bin/git"; +my $gittmp = "/tmp"; my $my_url = $cgi->url(); my $my_uri = $cgi->url(-absolute => 1); -mkdir($gittmp, 0700); - my $project = $cgi->param('p'); my $action = $cgi->param('a'); my $hash = $cgi->param('h'); my $hash_parent = $cgi->param('hp'); my $time_back = $cgi->param('t'); -if (!(defined($time_back))) { - $time_back = 1; -} $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects"; -# sanitize input -$action =~ s/[^0-9a-zA-Z\.\-]//g; -$hash =~ s/[^0-9a-fA-F]//g; -$hash_parent =~ s/[^0-9a-fA-F]//g; -$time_back =~ s/[^0-9]+//g; +# validate input if (defined($project) && $project =~ /(^|\/)(|\.|\.\.)($|\/)/) { - print $cgi->header(-type=>'text/plain', -status=>'403 Permission denied'); - print "Malformed query, file missing or permission denied\n"; - exit 0; + error_page("403 Permission denied", "Invalid project parameter."); +} +if (defined($action) && !$action =~ m/^[0-9a-zA-Z\.\-]+$/) { + error_page("403 Permission denied", "Invalid action parameter."); +} +if (defined($hash) && !($hash =~ m/^[0-9a-fA-F]{40}$/)) { + error_page("403 Permission denied", "Invalid hash parameter."); +} +if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) { + error_page("403 Permission denied", "Invalid parent hash parameter."); +} +if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) { + error_page("403 Permission denied", "Invalid time parameter."); +} else { + $time_back = 1; } -$project =~ s/|//g; sub git_header_html { - print $cgi->header(-type => 'text/html', -charset => 'utf-8'); -print <header(-type=>'text/html', -charset => 'utf-8', -status=> $status); + print < @@ -104,7 +107,7 @@ print < EOF print "
\n" . - "" . + "" . "\"git\""; if ($defaultprojects ne "") { print $cgi->a({-href => "$my_uri"}, "projects") . " / "; @@ -128,6 +131,18 @@ sub git_footer_html { print "\n"; } +sub error_page { + my $status = shift || "403 Permission denied"; + my $error = shift || "Malformed query, file missing or permission denied"; + git_header_html($status); + print "
\n" . + "

\n"; + print "$error\n"; + print "
\n"; + git_footer_html(); + exit 0; +} + sub git_head { my $path = shift; open my $fd, "$projectroot/$path/HEAD"; @@ -580,10 +595,5 @@ if ($action eq "blob") { print "
"; git_footer_html(); } else { - git_header_html(); - print "
\n" . - "

\n"; - print "unknown action\n"; - print "
\n"; - git_footer_html(); + error_page("403 Forbidden", "unknown action"); }