From: Jakub Narebski <jnareb@gmail.com>
To: "Avery Pennarun" <apenwarr@gmail.com>
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Randal L. Schwartz" <merlyn@stonehenge.com>,
"Jeff King" <peff@peff.net>,
"Robert Schiele" <rschiele@gmail.com>,
git@vger.kernel.org, "Lea Wiemann" <lewiemann@gmail.com>,
"H. Peter Anvin" <hpa@zytor.com>, Petr Baudis <pasky@suse.cz>
Subject: Re: [PATCH] change Perl syntax to support Perl 5.6
Date: Sun, 31 Aug 2008 22:23:36 +0200 [thread overview]
Message-ID: <200808312223.38222.jnareb@gmail.com> (raw)
In-Reply-To: <32541b130808311129u79f4179enfabab8f5845ed522@mail.gmail.com>
On Sub, 31 August 2008, Avery Pennarun wrote:
> On Sun, Aug 31, 2008 at 12:27 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> merlyn@stonehenge.com (Randal L. Schwartz) writes:
>>
>>>>>>>> "Avery" == Avery Pennarun <apenwarr@gmail.com> writes:
>>>
>>> Avery> Shell quoting is a disaster (including security holes, where relevant)
>>> Avery> waiting to happen. The above is the only sane way to do it, and it
>>> Avery> isn't very hard to implement. (Instead of system() in the subprocess,
>>> Avery> you can use exec().)
>>>
>>> quotemeta() is about regex quoting. This is not precisely the same as shell
>>> quoting, and is both misleading, and potentially broken.
>>
>> Agreed to, and grateful for, both of your comments.
>>
>> Do you like the one Jakub quoted from how gitweb does it? It looks like
>> this:
>>
>> # 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'" } @_ ));
>> }
>
> No, that's just another feeble attempt at quoting, which may or may
> not be correct. I'm not smart enough to tell.
First, according to POSIX, for POSIX-compatibile shells we should have:
2. Shell Command Language
2.2 Quoting
2.2.2 Single-Quotes
Enclosing characters in single-quotes ( '' ) shall preserve the literal
value of each character within the single-quotes. A single-quote cannot
occur within single-quotes.
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02_02
So that is why single quote "'" must be escaped as "I'am" -> 'I'\''am'
(' -> '\'', i.e. close quote, escaped ' = \', (re-)open quote).
Second, as Lea Wrote in commit message for 516381d5:
gitweb: quote commands properly when calling the shell
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).
We have to go to quote.c to get to know why "!" is a special case too,
in addition to "'". The commit message for 77d604c3 (by H. Peter Anvin,
which is CC-ed) states:
Create function to sq_quote into a buffer
Handle !'s for csh-based shells
> I have a proper implementation in the 'runlock' script in gitbuilder:
>
> http://github.com/apenwarr/gitbuilder/tree/master/runlock
>
> In that particular case, I wanted to handle signals carefully, so I
> needed the manual fork thing even in perl 5.8. You can safely remove
> the signal handling stuff (and of course the lockfile stuff) if you
> just want a minimal safe fork-exec-wait implementation in perl.
But if we go this way, i.e. fork+exec (perhaps implicit fork), why do
not simply use appropriate commands from Git.pm (Git::Repo doesn't
have it yet, IIRC). As far as I remember Git.pm was created initially
to unify all different "safe_pipe" and "safe_cmd" implementations among
different Perl scripts in Git (Petr "Pasky" Baudis CC-ed).
--
Jakub Narebski
Poland
next prev parent reply other threads:[~2008-08-31 20:24 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-30 17:39 [PATCH] change Perl syntax to support Perl 5.6 Robert Schiele
2008-08-30 18:00 ` Jeff King
2008-08-30 18:06 ` Junio C Hamano
2008-08-30 18:13 ` Jeff King
2008-08-30 18:34 ` Robert Schiele
2008-08-30 18:39 ` Jeff King
2008-08-30 20:37 ` Jakub Narebski
2008-08-30 21:21 ` Robert Schiele
2008-08-31 5:35 ` Avery Pennarun
2008-08-31 13:37 ` Randal L. Schwartz
2008-08-31 16:27 ` Junio C Hamano
2008-08-31 18:29 ` Avery Pennarun
2008-08-31 20:23 ` Jakub Narebski [this message]
2008-08-31 20:34 ` Petr Baudis
2008-09-01 3:57 ` H. Peter Anvin
2008-09-01 4:22 ` Robert Schiele
2008-09-01 13:06 ` Tom G. Christensen
2008-09-04 17:28 ` Brandon Casey
2008-09-05 6:34 ` Tom G. Christensen
2008-08-31 20:55 ` Jakub Narebski
2008-09-01 1:52 ` Jay Soffian
2008-09-01 21:42 ` Alex Riesen
2008-09-02 0:23 ` Avery Pennarun
2008-09-02 17:50 ` Avery Pennarun
2008-08-30 20:20 ` Junio C Hamano
2008-08-31 13:35 ` Randal L. Schwartz
2008-08-31 19:54 ` Ask Bjørn Hansen
2008-09-01 1:22 ` Junio C Hamano
2008-09-01 1:48 ` Junio C Hamano
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=200808312223.38222.jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=apenwarr@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hpa@zytor.com \
--cc=lewiemann@gmail.com \
--cc=merlyn@stonehenge.com \
--cc=pasky@suse.cz \
--cc=peff@peff.net \
--cc=rschiele@gmail.com \
/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).