Mar 15
Today, I had to debug a crash which was caused by a developer providing an untrusted string to a printf() function. This string had escape sequences in it which caused printf() to start popping parameters off the stack when no such parameters existed. While I was fortunate in that the crash was immediate and reproducible, I must note the following:
- DO NOT DO THIS. Either use
printf("%s", str);or one of theputs()functions. - Variable-argument functions are inherently brittle and crash-prone.
- If you suspect the crash is due to a buffer-overflow problem such as this, and you are trying to debug after the behavior has already happened (for example, after the access violation exception has been thrown) don’t blindly trust the values of any variables the debugger tells you after this point, as the stack is likely garbage.
Recent Comments