How to create the condition of stack overflow in GNU/linux?
-
See: stackoverflow.com/questions/294050/how-does-a-stack-overflowCan Berk Güder– Can Berk Güder2008-12-25 17:01:11 +00:00Commented Dec 25, 2008 at 17:01
-
This is very nearly a dupe of stackoverflow.com/questions/62188/…Adam Rosenfield– Adam Rosenfield2008-12-25 17:15:05 +00:00Commented Dec 25, 2008 at 17:15
8 Answers
a recursive function with no way out should do the trick
pseudo-code, my c is a bit rusty
void stack_overflow()
{
stack_overflow();
}
2 Comments
I'd recommend reading the phrack magazine article "Smashing the stack for fun and profit". It also contains sample code.
Comments
You just need to think about what uses the stack in C.
- Dynamic memory allocation (with
malloc()) uses the heap; - Local variables and function call stacks use the stack.
So, all you have to do is exhaust the stack. Either endless recursion on a function or large local variable creation (don't let them be cleaned up though by going out of scope) should do it.
Comments
There are code samples in the Wikipedia article. Why you'd want to cause one is beyond me...
1 Comment
Lot of examples have been referred here in other answers. But every one seems to have missed this.
To force the stack overflow, one needs to understand what is the size of your stack. In linux the default size of the stack is 8MB.
ulimit -a //would give you the default stack size
ulimit -s 16384 // sets the stack size to 16M bytes
So you can force the stack overflow even with an array of say 100 integers , if you tweak the stack size to be that much small.