http://qs1969.pair.com?node_id=197030

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