Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
A buffer overflow occurs when a program writes more data into a memory buffer than it can hold, corrupting adjacent memory and sometimes handing control to an attacker.

What Is a Buffer Overflow?
A buffer overflow happens when a program writes more data into a fixed-size block of memory than was allocated for it, spilling into adjacent memory. Depending on what gets overwritten, the result ranges from a crash to full remote code execution. It is one of the oldest vulnerability classes in computing and, in languages such as C and C++, still one of the most damaging.
Programs hold data in buffers—arrays of a fixed length. C does not check array bounds automatically, so a function such as strcpy() will copy however many bytes it is given:
void greet(const char *name) {
char buf[16];
strcpy(buf, name); /* no length check */
puts(buf);
}
Pass in a 100-character name and the extra 84 bytes overwrite whatever sits next to buf on the stack. On many architectures that includes the saved return address. If an attacker controls those bytes, they control where the function “returns” to—and therefore what code runs next.
MITRE’s weakness list files the core flaws under CWE-787 (Out-of-bounds Write) and CWE-120 (Classic Buffer Overflow), and out-of-bounds writes have been among the very top entries of the CWE Top 25 Most Dangerous Software Weaknesses in recent years.
| Year | Incident | Overflow involved |
|---|---|---|
| 1988 | Morris worm | Stack overflow in the Unix fingerd service |
| 2001 | Code Red | Overflow in an indexing service extension for Microsoft IIS |
| 2003 | SQL Slammer | Overflow in the SQL Server Resolution Service, spreading worldwide within minutes |
| 2017 | WannaCry | EternalBlue (CVE-2017-0144), an SMBv1 memory corruption flaw; the outbreak disrupted NHS trusts across England |
Exploiting an overflow today is far harder than in 1996, thanks to layered protections in compilers and operating systems:
-fstack-protector-strong, MSVC’s /GS).Attackers respond by chaining an information leak, which defeats ASLR, with ROP gadgets that sidestep DEP. Mitigations raise the cost of exploitation; they do not remove the bug.
The durable fix is not to write the bug in the first place. Microsoft and the Chromium project have both reported that around 70% of their serious security bugs are memory-safety issues. In December 2023 the NCSC joined CISA, the NSA, and other Five Eyes agencies in publishing “The Case for Memory Safe Roadmaps”, urging vendors to plan a move to memory-safe languages such as Rust, Go, C#, and Java. For existing C and C++ code:
gets, strcpy, and sprintf, and use bounded alternatives.MITRE ATT&CK captures how these bugs are used in practice: T1190 Exploit Public-Facing Application for internet-facing services and T1203 Exploitation for Client Execution for documents and browsers. Successful exploitation often leads straight to privilege escalation when the vulnerable process runs as root or SYSTEM.
Overflows in firmware, embedded devices, and legacy services often survive simply because nobody has tested them. Our infrastructure security testing looks for exactly those exposed, unpatched services before an attacker does.
Yes. Modern mitigations make exploitation harder, but overflows keep appearing in VPN appliances, firewalls, routers, browsers, and embedded firmware, much of it written in C or C++. Several edge-device vulnerabilities exploited by ransomware groups and state actors in recent years were memory corruption bugs. Until large codebases move to memory-safe languages, overflows will remain a regular source of critical CVEs.
Code written purely in memory-safe languages such as Python, Java, C#, Go, or safe Rust is protected by bounds checking, so a classic overflow raises an exception instead of corrupting memory. However, these runtimes and many popular libraries contain native C or C++ components, and an overflow in that native code can still be exploited through your application. Keeping interpreters and native dependencies patched therefore still matters.
For third-party products, track vendor advisories and CVEs and scan your estate for affected versions. For in-house C or C++ code, combine static analysis, compiler warnings, AddressSanitizer test builds, and fuzzing, then commission a code review or penetration test for high-risk components such as parsers and network services. Binary analysis can also check whether compiled programs were built with canaries, ASLR, and DEP enabled.
A buffer overflow writes or reads outside the boundaries of allocated memory, corrupting neighbouring data or exposing it, and can lead to code execution. A memory leak is memory that a program allocates and never releases, so usage grows until performance degrades or the process crashes. Leaks are mainly a reliability problem, although attackers can sometimes exploit them to exhaust resources and cause denial of service.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.