Why the Stack Matters

When a program runs, its memory splits into regions: the text segment (executable code), the data segment (globals/statics), the heap (grows upward, dynamically allocated), and the stack (grows downward, holds function call frames).

Every function call pushes a new stack frame containing local variables, the saved base pointer (EBP/RBP), and the return address — the address execution jumps back to once the function finishes. That return address is the target of a classic buffer overflow.

The Vulnerable Pattern

void vulnerable(char *input) {