Zennoxa Shield
Application Security Glossary

Buffer Overflow

A buffer overflow is a memory-safety vulnerability where a program writes more data into a fixed-size buffer than it can hold, overwriting adjacent memory and potentially corrupting data, crashing the application, or letting an attacker execute arbitrary code.

A buffer overflow happens when a program writes past the bounds of an allocated buffer — for example copying a long input into a fixed-size array without checking its length. The extra bytes spill into neighboring memory, overwriting other variables, pointers, or control data. In stack-based overflows this can clobber the saved return address; in heap-based overflows it can corrupt allocator metadata or adjacent objects. Both undermine the program's memory integrity.

Historically, buffer overflows are the archetypal memory-corruption exploit: by overwriting a return address or function pointer with an attacker-chosen value, an attacker can redirect execution to injected shellcode or, defeating non-executable memory, to existing code via return-oriented programming. This is why the class remains one of the most impactful in native software, cataloged as CWE-120 (classic buffer overflow) and CWE-787 (out-of-bounds write).

Buffer overflows arise almost exclusively in languages without automatic bounds checking, such as C and C++. Defenses include bounds-checked functions and length validation, compiler and OS mitigations (stack canaries, ASLR, non-executable stacks, and fortify checks), fuzzing and memory sanitizers, and — most durably — using memory-safe languages that check array bounds at runtime or compile time. For developers, careful handling of every buffer size and input length is essential in native code paths.

Frequently asked questions

What is a buffer overflow?
A buffer overflow is a vulnerability where a program writes more data into a fixed-size memory buffer than it can hold, overwriting adjacent memory. This can corrupt data, crash the program, or allow an attacker to overwrite control data and execute arbitrary code.
What is the difference between a stack and heap buffer overflow?
A stack buffer overflow overwrites data on the call stack, such as the saved return address, and is often exploited to redirect execution. A heap buffer overflow overwrites dynamically allocated memory, corrupting allocator metadata or adjacent objects. Both are out-of-bounds writes with serious security impact.
How do you prevent buffer overflows?
Validate input lengths and use bounds-checked APIs, enable compiler and OS mitigations such as stack canaries, ASLR, and non-executable memory, fuzz and test with memory sanitizers, and where possible use memory-safe languages that enforce array bounds automatically.

Related terms

Buffer Overflow — Zennoxa Glossary — Zennoxa Shield