Sat, 15 Jan 2005
Russian Roulette -- Bash Style
There are a list of things you don't want to see in your Unix machines
start up scripts but one of the leaders has to be a snippet like this:
[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live. For now."
Before we look at what the chunk of code is supposed to actually do it's worth mentioning that $RANDOM is a built-in shell variable. Each time it is read it will return a random integer between 0 and 32767. It's worth noting that although it's called $RANDOM it is no where near random enough to be used in any sensible crypto or security code / system.
Now back to the code itself, every time it runs you have a one in six chance of wiping your machine. It's not nice and once you know about $RANDOM it's not all that clever either.
Like this post? - Digg Me! | Add to del.icio.us! | reddit this!
Posted: 2005/01/15 11:40 | /codinghorrors | Permanent link to this entry | This entry + same date

