From: Ilya Zakharevich on
On 2010-08-01, John Kelly <jak(a)isp2dial.com> wrote:
>> /* handle the 2>&1 construct at the end */
>> if (*s == '>' && s[1] == '&' && s[2] == '1'
>> ...
>> if (!*t && (PerlLIO_dup2(1,2) != -1)) {
>> s[-2] = '\0';
>> break;
>> }
>> }
>
> Interesting it says "at the end"

> I wonder if placing it elsewhere in the command will circumvent Perl's
> shortcut and invoke a shell as usual.

At least with my initial implementation, only the position at the end
is special-cased.

Although your "as usual" looks suspicious. The *usual* case is a
shell-less execution. Only if shell metachars appear one is forced to
invoke the shell.

And, BTW, what would be your motivation to wish for a shell?

Yours,
Ilya
From: Ben Morrow on

Quoth John Kelly <jak(a)isp2dial.com>:
> On Sun, 1 Aug 2010 01:27:52 -0700 (PDT), "C.DeRykus" <derykus(a)gmail.com>
> wrote:
>
> >Yes, IIUC, it looks like there is a dup and the shell's
> >bypassed:
> >
> > From doio.c:
> >
> > /* handle the 2>&1 construct at the end */
> > if (*s == '>' && s[1] == '&' && s[2] == '1'
> > ...
> > if (!*t && (PerlLIO_dup2(1,2) != -1)) {
> > s[-2] = '\0';
> > break;
> > }
> > }
>
> Interesting it says "at the end"
>
> I wonder if placing it elsewhere in the command will circumvent Perl's
> shortcut and invoke a shell as usual.

No. Check the source if you're actually interested. '2>&1', with a space
before it and either a space or end-of-string after it, is ignored when
checking for shell special characters. It's only that exact string;
other shell redirections are left to the shell.

It may be worth noting that a command matching /^\.\s/, /^exec\s/ or
/^\w*=/ will also be passed to the shell[1].

Ben

[1] This is, of course, with *sane* semantics for \w and \s, viz.
[a-zA-Z0-9_] and [ \t\n\r\f] respectively, rather than the insane
Unicode semantics currently the default (some of the time).
From: Alan Curry on
In article <26dhi7-rm52.ln1(a)osiris.mauzo.dyndns.org>,
Ben Morrow <ben(a)morrow.me.uk> wrote:
>
>It may be worth noting that a command matching /^\.\s/, /^exec\s/ or
>/^\w*=/ will also be passed to the shell[1].

The mention of exec made me wonder about other shell builtins. All of the
following fail on my system, where they are builtin to /bin/sh and not
available as external commands:

perl -e 'system "eval ls /"'
perl -e 'system "command ls /"'
perl -e 'system "set"'
perl -e 'system "times"'
perl -e 'system "read foo"'

All of the above would produce output (or in the last case, consume input) if
they were executed properly. Luckily, none of them are likely to be used for
any reason except to demonstrate the fact that they don't work.

--
Alan Curry
From: John Kelly on
On Mon, 2 Aug 2010 00:47:03 +0000 (UTC), pacman(a)kosh.dhis.org (Alan
Curry) wrote:

>In article <26dhi7-rm52.ln1(a)osiris.mauzo.dyndns.org>,
>Ben Morrow <ben(a)morrow.me.uk> wrote:
>>
>>It may be worth noting that a command matching /^\.\s/, /^exec\s/ or
>>/^\w*=/ will also be passed to the shell[1].
>
>The mention of exec made me wonder about other shell builtins. All of the
>following fail on my system, where they are builtin to /bin/sh and not
>available as external commands:
>
>perl -e 'system "eval ls /"'
>perl -e 'system "command ls /"'
>perl -e 'system "set"'
>perl -e 'system "times"'
>perl -e 'system "read foo"'
>
>All of the above would produce output (or in the last case, consume input) if
>they were executed properly. Luckily, none of them are likely to be used for
>any reason except to demonstrate the fact that they don't work.

It's easy to force a shell with some no-op metacharacters:

perl -e 'system ":; eval ls /"'



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: John Kelly on
On Sun, 1 Aug 2010 23:17:37 +0000 (UTC), Ilya Zakharevich
<nospam-abuse(a)ilyaz.org> wrote:

>On 2010-08-01, John Kelly <jak(a)isp2dial.com> wrote:
>>> /* handle the 2>&1 construct at the end */
>>> if (*s == '>' && s[1] == '&' && s[2] == '1'
>>> ...
>>> if (!*t && (PerlLIO_dup2(1,2) != -1)) {
>>> s[-2] = '\0';
>>> break;
>>> }
>>> }
>>
>> Interesting it says "at the end"
>
>> I wonder if placing it elsewhere in the command will circumvent Perl's
>> shortcut and invoke a shell as usual.
>
>At least with my initial implementation, only the position at the end
>is special-cased.
>
>Although your "as usual" looks suspicious. The *usual* case is a
>shell-less execution. Only if shell metachars appear one is forced to
>invoke the shell.
>
>And, BTW, what would be your motivation to wish for a shell?

Most of the time, none. I was just wondering how things work. I like
the shell-less shortcut just fine.



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php