From: Lea Wiemann <lewiemann@gmail.com>
To: git@vger.kernel.org
Cc: Lea Wiemann <LeWiemann@gmail.com>
Subject: [PATCH v2] gitweb: quote commands properly when calling the shell
Date: Tue, 17 Jun 2008 23:46:35 +0200 [thread overview]
Message-ID: <1213739195-29284-1-git-send-email-LeWiemann@gmail.com> (raw)
In-Reply-To: <7vd4mg9824.fsf@gitster.siamese.dyndns.org>
This eliminates the function git_cmd_str, which was used for composing
command lines, and adds a quote_command function, which quotes all of
its arguments (as in quote.c).
Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---
Changed since v1: Quote the whole command line, safely.
I've tested that the object and snapshot actions still work (which is
where git_cmd_str was used), and I've hand-tested the quote_command
function. *wait-for-test-suite-to-appear-in-later-revisions*
Hope this addresses your concerns, Junio!
-- Lea
gitweb/gitweb.perl | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7b1b076..3a7adae 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1500,9 +1500,13 @@ sub git_cmd {
return $GIT, '--git-dir='.$git_dir;
}
-# returns path to the core git executable and the --git-dir parameter as string
-sub git_cmd_str {
- return join(' ', git_cmd());
+# quote the given arguments for passing them to the shell
+# quote_command("command", "arg 1", "arg with ' and ! characters")
+# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
+# Try to avoid using this function wherever possible.
+sub quote_command {
+ return join(' ',
+ map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
}
# get HEAD ref of given project as hash
@@ -4493,7 +4497,6 @@ sub git_snapshot {
$hash = git_get_head_hash($project);
}
- my $git_command = git_cmd_str();
my $name = $project;
$name =~ s,([^/])/*\.git$,$1,;
$name = basename($name);
@@ -4501,11 +4504,12 @@ sub git_snapshot {
$name =~ s/\047/\047\\\047\047/g;
my $cmd;
$filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
- $cmd = "$git_command archive " .
- "--format=$known_snapshot_formats{$format}{'format'} " .
- "--prefix=\'$name\'/ $hash";
+ $cmd = quote_command(
+ git_cmd(), 'archive',
+ "--format=$known_snapshot_formats{$format}{'format'}",
+ "--prefix=$name/", $hash);
if (exists $known_snapshot_formats{$format}{'compressor'}) {
- $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
+ $cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
}
print $cgi->header(
@@ -4718,8 +4722,8 @@ sub git_object {
if ($hash || ($hash_base && !defined $file_name)) {
my $object_id = $hash || $hash_base;
- my $git_command = git_cmd_str();
- open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
+ open my $fd, "-|", quote_command(
+ git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
or die_error('404 Not Found', "Object does not exist");
$type = <$fd>;
chomp $type;
--
1.5.6.rc3.7.ged9620
next prev parent reply other threads:[~2008-06-17 21:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-17 1:09 [PATCH] gitweb: fix support for repository directories with spaces Lea Wiemann
2008-06-17 1:14 ` Junio C Hamano
2008-06-17 21:27 ` Junio C Hamano
2008-06-17 21:46 ` Lea Wiemann [this message]
2008-06-17 21:51 ` [PATCH v2] gitweb: quote commands properly when calling the shell Lea Wiemann
2008-06-17 23:41 ` Junio C Hamano
2008-06-17 1:38 ` [PATCH] gitweb: fix support for repository directories with spaces Jakub Narebski
2008-06-17 22:07 ` Lea Wiemann
2008-06-17 22:27 ` Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1213739195-29284-1-git-send-email-LeWiemann@gmail.com \
--to=lewiemann@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).