How to overflow a stack without clicking new stack frames?

One obvious way to cause a stack to overflow and get it Segmentation faultis to recursively click freeze frames on each other until it forgets. I am wondering if the stack will overflow without even clicking on the new frames of the stack.

Creating a large enough array could do this from experience as well, but any other possible scenarios?

+5
source share
4 answers

C99 uses a resizable array, which you can use and resize it to a larger one. However, this scalable array is implemented using alloca. Here is a sample code on UNIX env :

#include <stdio.h>
#include <alloca.h>
#include <stdlib.h>
#include <stdbool.h>

int
main()
{
    while (true)
    {
        void *p = alloca(32UL);
        printf("new memory allocated at %p \n", p);
    }
    exit(EXIT_SUCCESS);
}

:

new memory allocated at 0xbf800a60 
new memory allocated at 0xbf800a30 
new memory allocated at 0xbf800a00 
new memory allocated at 0xbf8009d0 
new memory allocated at 0xbf8009a0 
[1]    3977 segmentation fault  ./a.out

alloca malloc, , , .

+3

alloca() _alloca(), Windows SDK/VS:

alloca() .

_alloca() _malloca().

+1

, "" - , , ESP/EBP .

:

  • , , : int x[10000000];
  • ESP : __asm mov esp, 0x0
  • , , , ESP/EBP : int x; memset(&x, 0, 10000000);

...

+1

, , :

$ ulimit -s
8192
$

int main(void)
{
    volatile char bla[8192 * 1024 + 16] = {0};
}

segfault will probably be executed when executed.

+1
source

All Articles