Thursday, January 12, 2006

favorite pet bug

Here's a simple program with some unexpected consequences. It works only on windows NT-based systems, including XP.
#include "stdio.h"
int main()
{
printf(" \b\b ");
return 0;
}
To get the full effect you have to run it by double-clicking on the icon, rather than from a DOS prompt. If you want one you can run from a command prompt, replace the printf above with:
while (1) printf(" \b\b");

An infinte loop isn't quite as elegant as a single statement that wreaks havoc on your system, but it's still simple enough. In order to generate the "desired" result, you have to backspace beyond the first character of the terminal window, then output a printing character to the left of the beginning of the buffer. Apparently cmd.exe doesn't check for this condition, and triggers an error in a system-critical process.

I remember Microsoft bragging about how DOS programs run in their own virtual machine, so a mis-behaved DOS app can't crash your computer. I think this example here is proof-positive to the contrary.

If anybody has any more technical information about the cause (and possibly history) if this bug, I'd love to hear it.

What's it do? Oh, yeah, it reboots your computer. No shutdown, no warning. Just like hitting the power switch.

And aren't you glad you paid over $1000 for MS server software that can be rebooted by any user who executes a 4-character printf?

0 Comments:

Post a Comment

<< Home