Skip to content
Fast-turnaround security assessments available — 10+ years development & security experienceGet started
Back to Glossary
Glossary2 min read

Buffer Overflow

A vulnerability where a program writes data beyond the boundaries of allocated memory, potentially enabling code execution or system crashes.

A buffer overflow occurs when a program writes more data to a memory buffer than it was allocated to hold. The excess data overwrites adjacent memory, corrupting data structures, altering program control flow, or enabling arbitrary code execution. Buffer overflows have been one of the most exploited vulnerability classes in computing history.

How It Works

Programs allocate fixed-size blocks of memory (buffers) to store data. When code copies data into a buffer without checking whether the input exceeds the buffer's capacity, the surplus data spills into neighboring memory regions. The consequences depend on what that adjacent memory contains.

Stack-based buffer overflows target buffers allocated on the call stack. The stack stores local variables alongside return addresses — the memory locations the program jumps to when a function finishes. By overflowing a stack buffer, an attacker overwrites the return address with a value pointing to their injected code. When the function returns, execution jumps to the attacker's payload instead of the legitimate caller.

Heap-based overflows target dynamically allocated memory. While exploitation is more complex, corrupting heap metadata or adjacent heap objects can lead to arbitrary write primitives, which attackers use to gain code execution through techniques like overwriting function pointers or vtable entries.

Integer overflows are a related class where arithmetic operations produce values larger than the variable can hold, wrapping around to unexpected small values. When these values are used to calculate buffer sizes, they result in undersized allocations that are subsequently overflowed.

Modern Mitigations

Operating systems and compilers implement multiple defenses. Address Space Layout Randomization (ASLR) randomizes memory locations, making it difficult to predict where injected code or useful gadgets reside. Stack canaries place sentinel values before return addresses and detect overwrites. Data Execution Prevention (DEP) marks memory regions as non-executable. Despite these protections, exploitation techniques like Return-Oriented Programming (ROP) chain existing code fragments to bypass DEP, and information leaks defeat ASLR.

Why It Matters

Buffer overflows remain relevant in systems programming, embedded devices, and any software written in memory-unsafe languages. They are the foundation for many of the most severe exploits, from operating system privilege escalation to remote code execution in network services.

Need your application tested? Get in touch.

Need your application tested?

We find these vulnerabilities in real applications every day.

Request an Assessment