Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of jjore (6662)

Monday February 23, 2009
12:56 AM

<>'s bad touch

[ #38534 ]

It took fifteen minutes of misreading the bash manual to write a filename that perl will execute as "touch /" when using <>, -p, or -n.

$ touch 'touch $'\''\x2f'\''|'
$ ls
touch $'\x2f'|
$ perl -pee *
touch: /: Permission denied

As explanation, the filename is used by perl's two-arg open by perl's magic <> by perl's -p command line paramter.

while (<>) {
    'e';
}

When it comes to reading the file, it runs something like this:

open ARGV, q{touch $'\x2f'|};

Since it ends in a pipe, perl's going to fork, run the command without the pipe and then read from it. Usually you'd use it for stuff like "zcat $filename |" for automatic decompression or whatever.

It's running something like:

sh -c 'touch $'\''\x2f'\'

which when run by sh is

touch $'\x2f'

after shell decoding is...

touch /

This is supposed to be a feature. Huzzah, I guess. I'm told that because it was once documented as feature, it can't be considered a bug and fixed. :-(

Just for giggles, my current directory was also named <>.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.