Argh, forgot my password....
Anyway, the problem with using backticks is that whatever
is between the backticks is going to be pass to a shell,
so if you interpolate a var with data read from the user,
you can do whatever you want. Example: try your code with<
mail; touch jejejejeje <code>
as the input
A safer, but more convoluted, way to do this is using open
with "-|":
<code>open (DA, "-|") || exec "du", "$dir";
@output = <DA>;
This will fork a process; in the parent, the exec isnt going
be executed, as the return of the open will be the PID of the
child, and the child will just exec du with the content of
$dir as first arg, without passing anything through a shell.
In the previous example, it would give you an error:
du: mail;touch jejejej: No such file or directory
Yes, its more complex, and you may think its unnecessary in
your current application, but its better to know a safer
way to do it and the risks of the "unsafe" way, to have
it in mind if, say, you end up attaching this to a CGI or
something.
Good luck
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.