How to debug a corrupted stack

Interview questions

Is your stacktrace really corrupted?

by Salvatore Iovene on 17 October 2006 — Posted in HowtosCodingArticles

You may encounter, during your debugging sessions, the `stack corruption’ problem. Usually you will find it out after seeing your program run into a segmentation fault. Otherwise, it must mean that some very malicious and subtle code has been injected into your program, usually through a buffer overrun. What is a buffer overrun? Let’s examine the following short C code:

#include <stdio.h>

void bar(char* str) {
    char buf[4];
    strcpy( buf, str );

void foo() {
    printf("Hello from foo!");

int main(void) {
    bar("This string definitely is too long, sorry!");
    return 0;

There’s clearly something wrong with it: as you can see, we are copying `str’ to `buf’ without first checking the size of `str’. First of all there is a security issue, because if `str’ didn’t just…

View original post 1,036 more words