I am seeking a common example whereby (!) the stack is destroyed in a C program. I use GCC in Ubuntu.
It depends on what you mean by "destroy the stack", but this is a common error that will generally cause corruption of vital stack-resident data:
void dumb()
{
char small[2];
strcpy(small, "too long to fit"); // Writes past the end of "small", overwriting vital information
}
This is a common source of security holes. It can potentially be used to hijack the instruction pointer, enabling malicious code to execute. See buffer overflow.
Another mistake that might be described as "destroying the stack" is the case of infinite recursion (scroll down on that page):
int add(int n)
{
return n + add(n + 1);
}
Which, as it lacks an exit condition, will push so many frames onto the stack that it eventually gets "full". (Unless the compiler can apply tail-call optimization; see below)
Both of these examples compile without as much as a warning using GCC 4.4.3.
Note: As Billy ONeal pointed out below, the behavior of these examples is specific to x86, not C as a language, and may vary from one compiler to another. That is not to say that they don't demonstrate how you can break the stack in a particular (and extremely common) implementation of C.