From: Nala Ginrut <nalaginrut@gmail.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: [Proposal] Why not add a "shell" procedure?
Date: Mon, 14 May 2012 08:17:43 +0800 [thread overview]
Message-ID: <CAPjoZodT6eXkNp7ugpZJQQPqs4a9W+GxceK+ozdT_cNzrnDRoA@mail.gmail.com> (raw)
In-Reply-To: <87y5owkk93.fsf@netris.org>
hi Mark! Thanks for reply!
One reason to proposal this "shell" is to handle these metacharacters
in programming way. I think it's easier than input them with keyboard.
So my vote is to provide a more safer "shell" and encourage it rather
than using raw "open-pipe*".
What do you think?
On Mon, May 14, 2012 at 2:29 AM, Mark H Weaver <mhw@netris.org> wrote:
> Hi Nala,
>
> Nala Ginrut <nalaginrut@gmail.com> writes:
>> (define %current-shell (getenv "SHELL"))
>> (use-modules (ice-9 popen) (rnrs io ports))
>> (define shell
>> (lambda (cmd)
>> (let ((str (string-append %current-shell " -c " cmd)))
>> (get-string-all (open-pipe str OPEN_READ)))))
>
> (open-pipe <STRING> ...) already does '/bin/sh -c <STRING>', so (shell
> <STRING>) does '/bin/sh -c "<SHELL> -c <STRING>"', i.e. it launches a
> shell within a shell. This is wasteful, and might also exacerbate
> problems when shell metacharacters are present in <STRING> or <SHELL>.
>
> Therefore, better do (open-pipe* OPEN_READ %current-shell "-c" cmd)
> instead.
>
> Also, I recommend making '%current-shell' a fluid, and perhaps adding a
> keyword argument to 'shell' to specify the shell directly, so that
> '%current-shell' is only used as the default for the keyword argument.
>
> Note that although it is convenient to pass strings directly to the
> shell, it is fraught with security risks due to the complexity of
> escaping shell metacharacters properly, especially given the diversity
> of shells and shell configurations. Therefore, it is better not to
> encourage this way of doing things. It is generally better to use
> 'open-pipe*' or 'system*' directly, to avoid the shell entirely.
>
> Thanks,
> Mark
next prev parent reply other threads:[~2012-05-14 0:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-12 12:30 [Proposal] Why not add a "shell" procedure? Nala Ginrut
2012-05-12 12:35 ` Nala Ginrut
2012-05-12 14:22 ` Thien-Thi Nguyen
2012-05-13 15:04 ` Nala Ginrut
2012-05-13 18:29 ` Mark H Weaver
2012-05-14 0:17 ` Nala Ginrut [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-05-12 14:37 Nelson H. F. Beebe
2012-05-13 15:08 ` Nala Ginrut
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPjoZodT6eXkNp7ugpZJQQPqs4a9W+GxceK+ozdT_cNzrnDRoA@mail.gmail.com \
--to=nalaginrut@gmail.com \
--cc=guile-devel@gnu.org \
--cc=mhw@netris.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 read-only IMAP folder(s) and NNTP newsgroup(s).