Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: How to delete a file with a print statement

by ikegami (Pope)
on Jul 31, 2006 at 16:44 UTC ( #564798=note: print w/replies, xml ) Need Help??

in reply to How to delete a file with a print statement

print is an innocent bystander here. No string passed to print will cause rm to execute. The `...` operator is being executed while building the string to pass to print. You could remove the print and you would get the same result.

> perl -Te "print qq{$var{die()}}" Died at -e line 1. > perl -Te "qq{$var{die()}}" Died at -e line 1.

A string literal (as opposed to a string) is a form of code. In fact, quotes, qq and the other string literal delimiters are listed as operators in perlop. Like other operators, the compiler (perl or eval EXPR) is required to convert them and their operands into executable form. String literal are only string literals in the context of source code, and will not get executed unless they are first compiled.

Most string literals result in code that simply returns a constant string ("Hello World!\n") or in code that performs concatenation ("Hello $name!\n"). However, it is well known that string literals can excute arbitrary code using the reference-dereference-array trick you mentioned. There are other ways.

perl -e "print qq{... @{[ ...arbitrary Perl expr... ]} ...}" perl -e "print qq{... ${ ...arbitrary Perl expr... } ...}" perl -e "print qq{... $var{ ...arbitrary Perl expr... } ...}" perl -e "print qq{... $var[ ...arbitrary Perl expr... ] ...}"

I wouldn't call this a new security hole, since eval is needed to exploit it.

Updated for readability and clarity, but no changes were made to the substance of the post.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://564798]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2021-04-15 17:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found