Tuesday, October 16, 2007

rm -rf /* Windows Style

As geeks, we've all heard the horror stories of some n00b killing a Unix box with a single command run as root:

rm -rf /*

But surely such things don't happen in the real world, right?

Today a coworker, Bob, asked me what a certain "clean.bat" DOS script was supposed to do. Imagine my surprise (and horror) when I opened the script in an editor:

del /S *.pdb
del /S *.ilk
del /S *.exe
del /S *.obj
del /S *.dll
del /S *.lib
del /S *.exp
del /S *.dep
del /S *.idb
del /S *.manifest
del /S *.res
del /S *.htm
del /S *.tlh
del /S *.tli

It turned out that another developer on my team, Derrik, had managed to slip this little devil into CM amongst the header files we ship with our product. When run from Derrik's sandbox the script helpfully deletes all of the intermediate files left behind by Visual Studio, thus allowing Derrik to do a nice clean recompile.

If the script is accidentally double clicked, however, the little beast runs on the C: drive and deletes all of those pesky applications you have installed. Then it deletes a good portion of Windows itself. Eventually it deletes something it depends on and dies. So does your PC.

Bob found this out the hard way. :(