A monk was recently asking the Chatterbox population how to get their adduser command to work correctly, and provided a code snippet similar to this:

system("adduser $username -c $realname");
In an attempt to provide a blatantly obvious example of why that code should be considered a Bad Thing (tm), I foolishly answered:

$realname = "bob; rm -r /"; system("adduser $username -c $realname");
Luckily, the pandemonium that ensued turned out to be a joke at my expense. But the lessons learned are real:

  1. "Blatantly obvious" isn't, in the chatterbox. The person reading your chats or posts might not understand you're kidding.
  2. If you post code, there's always a chance, no matter how small, that someone will run it. As root. On a production server. At 5pm on a Friday afternoon before a long weekend, when you're manning the pager. So don't post coode that you don't want people to run, even if it's completely obvious that you don't want people to run it (see #1).
  3. Don't run code that you don't understand. This can be a bit tricky when obfuscation is involved.
  4. If you "have" to run code that you don't understand, at least don't run it as root.
Alan

In reply to "Don't try this at home" by ferrency

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.