What Is a Buffer Overflow?

On this page
  1. How does the classic attack work?
  2. What stops buffer overflows today?

A buffer overflow occurs when a program writes more data into a fixed-size memory buffer than it was built to hold, spilling into neighboring memory. At best this crashes the program; at worst, a carefully crafted overflow overwrites control data and hijacks execution. It is one of the oldest and most studied vulnerability classes, and understanding it explains much of how exploitation works.

How does the classic attack work?#

Consider a program copying user input into a small stack buffer without checking length. The stack also holds the function’s return address — where the CPU jumps when the function finishes. Overflow the buffer far enough and you overwrite that return address:

[ buffer ][ saved registers ][ return address ]
   ^ attacker input flows this way →
   overwrite the return address → CPU jumps where the attacker chose

By overwriting the return address to point at attacker-supplied instructions (or, with modern mitigations, at existing code reused cleverly), the attacker turns a memory bug into arbitrary code execution — the payload stage.

What stops buffer overflows today?#

Layered mitigations have made naive exploitation much harder:

DefenseEffect
Stack canariesDetect overwrites before the function returns
DEP / NXMark data memory non-executable
ASLRRandomize addresses so payloads can’t hardcode them
Memory-safe languagesPrevent the class entirely (Rust, Go)
Bounds checking / safe APIsStop the overwrite at the source

Buffer overflows are the archetypal memory-safety flaw, often found via fuzzing. More at the Security Fundamentals hub.

Frequently asked questions#

What is a buffer overflow?

A buffer overflow happens when a program writes more data into a fixed-size memory buffer than it can hold, spilling into adjacent memory. That corruption can crash the program or, when carefully crafted, overwrite control data like a return address to redirect execution into attacker-supplied code.

Why are buffer overflows less common now?

Modern mitigations make them much harder: stack canaries detect overwrites, DEP/NX marks memory non-executable, and ASLR randomizes addresses so payloads cannot rely on fixed locations. Memory-safe languages like Rust and Go prevent the class outright. They still occur in C/C++ code, but exploitation takes far more work.

Sources & further reading