Creature

How do I create a condition in GNU / linux?

0


source to share


8 answers


a recursive function without exiting should do the trick

pseudocode, my c is a little rusty



void stack_overflow()
{
   stack_overflow();
}

      

+12


source


I would recommend reading the "Split the stack for fun and profit" article from phrack magazine . It also contains sample code.



+9


source


There are code examples in the Wikipedia article . Why do you want to call one because of me ...

+4


source


You just need to think about what is using the stack in C.

  • malloc()

    Heap allocation (c ) uses the heap;
  • Local variables and function call stacks use a stack.

So, all you have to do is pop the stack. Either infinite recursion over the function, or creating large local variables (don't let them get cleaned up though, going out of scope) should do this.

+4


source


With alloca () or strdupa ()

+1


source


Several examples have been given here in other answers. But everyone seems to have missed it.

To force a stack overflow, you need to understand what the size of your stack is. On linux, the default stack size is 8MB.

 ulimit -a         //would give you the default stack size 
 ulimit -s 16384   // sets the stack size to 16M bytes

      

This way you can force a stack overflow even with an array of 100 integers if you tune the stack size so small.

+1


source


The easiest way is to simply declare a sufficiently large automatic stack variable. No recursion or alloca required. Interestingly, this is not a compile-time error. The required size depends on the platform:

#define SIZE 10000000

int main(int argc, char **argv)
{
    char a[SIZE];
}

      

0


source


"how to create a condition in linux"

Similarly, you must create a stack overflow on Windows.

Jason's answer may work, but some compilers optimize it in a loop. I think adding a parameter will do the trick:

    int Add(int num)
    {
        num += Add(num);
        return num;
    }

      

0


source







All Articles