How Out-of-Bounds Write Vulnerabilities (CWE-787) Can Compromise Your Code — And Your Business
In the realm of software security, vulnerabilities present a significant risk to both businesses and users. The Common Weakness Enumeration (CWE) Top 25, compiled by the MITRE Corporation, highlights the most dangerous software weaknesses that threaten the integrity of applications and systems. Among these weaknesses is the Out-of-Bounds Write vulnerability, designated as CWE-787.
For software developers and architects, understanding the ins and outs of this vulnerability is critical. Out-of-bounds writes can lead to severe consequences such as system crashes, data corruption, and, in the worst case, remote code execution. These issues not only compromise the safety of applications but also have tangible business implications, including financial losses, reputational damage, and legal ramifications.
In this blog post, we will explore the Out-of-Bounds Write (CWE-787) vulnerability in depth. We will break down its causes, impacts, and methods of mitigation, providing practical insights for developers and architects seeking to design secure, robust applications.
What is Out-of-Bounds Write (CWE-787)?
An out-of-bounds write occurs when a program writes data outside the bounds of allocated memory. This typically happens when the application fails to correctly validate or manage memory allocations. When the program attempts to write to an area of memory that it does not own or have permission to access, it can overwrite critical data or control structures in memory.
In a well-structured application, memory access should be carefully managed, with checks in place to ensure that writes happen within allocated bounds. However, when this process is neglected or poorly implemented, it opens the door to a host of vulnerabilities. These can result in unpredictable behaviour, including system crashes, data corruption, and security breaches.
How Out-of-Bounds Write Occurs
To understand how out-of-bounds writes occur, it’s essential to grasp the basics of memory allocation and boundaries:
- Memory Allocation: In most programming languages, when data is allocated (whether through a buffer, array, or heap object), a specific region of memory is reserved for that data.
- Boundaries: These allocated memory regions have a defined size, and any attempt to read or write outside this space leads to an out-of-bounds operation.
- Unchecked Memory Access: Without proper checks (e.g., bounds checking), a developer may unintentionally allow a write operation to overflow or underflow the allocated memory, resulting in an out-of-bounds write.
An example of a common scenario where this occurs is in C or C++ when handling arrays. If a developer writes beyond the array’s defined size, it results in writing to an unintended area in memory.
Business Impact of Out-of-Bounds Write Vulnerabilities
While the technical aspects of out-of-bounds write vulnerabilities are well-documented, the real-world impact can be much more profound. Here are some key business concerns:
1. Reputation Damage
Security vulnerabilities can tarnish a company’s reputation. When a product is compromised due to an out-of-bounds write, it can lead to a loss of user trust, media backlash, and reduced customer confidence. Customers and clients expect software to be secure and reliable, and discovering a vulnerability may result in negative press, particularly if the issue affects a large user base.
2. Legal and Compliance Ramifications
If a security flaw leads to data breaches, intellectual property theft, or violations of compliance requirements (such as GDPR or HIPAA), a business can face legal action, hefty fines, and severe damage to its reputation. Ensuring secure code and preventing vulnerabilities like out-of-bounds writes can mitigate these risks and demonstrate due diligence to stakeholders and regulators.
3. Financial Costs
Fixing vulnerabilities in post-production software is significantly more expensive than addressing them during the development process. The cost of patching, legal settlements, public relations campaigns, and lost sales can be catastrophic for a company. Preventing security issues by understanding and mitigating out-of-bounds write vulnerabilities can result in significant cost savings in the long term.
4. Risk of Exploitation
In some cases, out-of-bounds writes can be exploited by attackers to gain control over the system, execute arbitrary code, or launch denial-of-service (DoS) attacks. These attacks can have dire consequences, including data breaches, service outages, and system compromises. Protecting against such vulnerabilities should be a priority for software developers and architects who wish to reduce the attack surface and minimise the risk of exploitation.
How Out-of-Bounds Write Vulnerabilities Are Exploited
An out-of-bounds write vulnerability is often a stepping stone for more severe attacks. In many cases, attackers exploit these weaknesses to perform various types of attacks, including:
1. Arbitrary Code Execution (ACE)
When an attacker successfully writes data to an out-of-bounds memory location, they may overwrite function pointers or return addresses, leading to arbitrary code execution. This can allow the attacker to execute malicious code within the context of the compromised application, effectively gaining control of the affected system.
For instance, if an attacker can write data to the memory location of a return address in a stack buffer, they could redirect program execution to their own malicious code, allowing them to take full control of the application.
2. Denial of Service (DoS)
By writing invalid data to memory locations outside the bounds of allocated space, an attacker could cause the application to crash or behave unpredictably, resulting in a denial of service. This type of attack can be especially disruptive in critical systems where uptime is vital.
3. Data Corruption
Out-of-bounds writes may lead to data corruption, which can affect the integrity of databases, configuration files, or sensitive information stored in memory. This can lead to malfunctioning applications, lost data, and incorrect outputs, causing reputational damage and financial losses for businesses.
4. Privilege Escalation
In some instances, attackers can exploit out-of-bounds writes to manipulate user permissions or gain escalated privileges. By corrupting sensitive structures like access control lists (ACLs), they could gain higher-level access within a system, leading to further security breaches.
Mitigating the Risks of Out-of-Bounds Write Vulnerabilities
For software developers and architects, mitigating the risks associated with out-of-bounds write vulnerabilities requires a multi-faceted approach. Below are key strategies to prevent and address these vulnerabilities:
1. Input Validation
Ensuring that all inputs to an application are thoroughly validated is a fundamental security measure. Developers should implement strict bounds checking to ensure that data written to buffers or arrays does not exceed the allocated memory.
For example, when handling user input, it’s crucial to ensure that the input does not exceed the buffer size allocated for it. In C/C++, functions like strncpy() (instead of strcpy()) or snprintf() (instead of sprintf()) can be used to prevent overflow vulnerabilities.
2. Safe Memory Management
Proper memory management is essential for preventing out-of-bounds write vulnerabilities. Developers should use dynamic memory allocation techniques that ensure proper bounds checking and avoid manual memory handling errors.
In languages like C, developers should consider using safer memory allocation functions and avoid directly manipulating memory addresses whenever possible. Alternatively, using high-level languages that manage memory automatically, like Python or Java, can reduce the likelihood of such vulnerabilities.
3. Static and Dynamic Analysis Tools
Utilising static and dynamic analysis tools is an effective way to detect and mitigate out-of-bounds write vulnerabilities early in the development lifecycle.
- Static Analysis: Tools such as SonarQube and Coverity can scan the source code for potential vulnerabilities, including out-of-bounds writes, by identifying patterns that could lead to unsafe memory access.
- Dynamic Analysis: Tools like Valgrind and AddressSanitizer can be used during runtime to detect out-of-bounds writes and memory access violations that may not be evident through static code inspection.
4. Compiler Security Features
Modern compilers come equipped with features that help protect against out-of-bounds writes. For example, enabling Stack Canaries and Control Flow Integrity (CFI) can help detect and prevent attacks that rely on memory corruption.
Additionally, Address Space Layout Randomisation (ASLR) is a defence mechanism that makes it more difficult for attackers to predict memory addresses, making out-of-bounds write vulnerabilities harder to exploit.
5. Buffer Overflow Protection
Implementing buffer overflow protection techniques such as SafeStack (which uses a separate stack for local variables) and Non-Executable Stack (which prevents code from being executed on the stack) can significantly reduce the risk of exploitation through out-of-bounds writes.
6. Use of High-Level Languages
Where possible, developers should consider using high-level programming languages that handle memory allocation automatically and provide stronger bounds-checking mechanisms. Languages like Java and Python offer built-in protections against out-of-bounds writes, significantly reducing the attack surface.
Real-World Examples
Example 1: The Heartbleed Bug
One of the most notorious vulnerabilities in recent history, the Heartbleed bug, was caused by improper bounds checking in the OpenSSL library. The vulnerability allowed attackers to read arbitrary memory from affected systems, exposing sensitive data such as passwords, private keys, and other secrets. Although not a classic out-of-bounds write, Heartbleed exploited improper bounds checking to access memory outside of allocated boundaries.
Example 2: The WannaCry Ransomware Attack
While not directly related to out-of-bounds writes, the WannaCry ransomware attack is another example of the devastating impact of security flaws in software. Vulnerabilities in Microsoft Windows, such as improper validation of network requests, allowed the malware to spread rapidly. Addressing vulnerabilities like out-of-bounds writes could have prevented similar exploits from occurring in the first place.
Real-World Cyber Incidents and Breaches Related to Out-of-Bounds Write (CWE-787)
Out-of-bounds write vulnerabilities (CWE-787) have been responsible for several high-profile cyber incidents over the years, often leading to catastrophic consequences for businesses and their customers. These vulnerabilities, while sometimes overlooked during development, can have far-reaching implications, including system crashes, data breaches, and remote code execution (RCE) — all of which can be exploited by malicious actors to compromise an organisation’s security posture.
In this section, we will examine notable real-world incidents where out-of-bounds write vulnerabilities have played a significant role in cyber breaches, highlighting the lessons learned and the importance of addressing such weaknesses during the software development lifecycle.
1. The Heartbleed Bug (OpenSSL)
Although Heartbleed (CVE-2014-0160) is most often classified as a buffer over-read vulnerability, it shares many characteristics with out-of-bounds write flaws and is a relevant case for understanding the risks posed by memory management errors. Discovered in April 2014, Heartbleed affected OpenSSL, a widely used cryptographic library in various secure communications protocols such as HTTPS.
- Cause: Heartbleed was caused by improper bounds checking in the OpenSSL implementation of the TLS/DTLS heartbeat extension. The bug allowed attackers to request up to 64 KB of memory from a vulnerable server without properly validating the bounds of the memory being read, which could leak sensitive data like private keys, session cookies, and user credentials.
- Impact: While Heartbleed primarily exploited a read issue, the underlying cause — improper handling of memory boundaries — is closely tied to how out-of-bounds operations can lead to severe security flaws. The breach affected millions of websites, including large-scale organisations like Google, Yahoo, and the US Department of Defense. The leaked information posed a severe risk to confidentiality and integrity, leaving systems vulnerable to further exploitation, such as man-in-the-middle (MITM) attacks.
- Lessons Learned: The Heartbleed incident reinforced the need for rigorous bounds checking, especially in cryptographic and network-related code. It also highlighted the dangers of libraries that are reused across many different applications without appropriate security audits.
2. Microsoft Windows SMBv3 (CVE-2020-0796)
In early 2020, Microsoft announced a critical vulnerability in the SMBv3 (Server Message Block) protocol, tracked as CVE-2020-0796. This vulnerability was due to an out-of-bounds write in the SMBv3 compression feature, which could be exploited by attackers to execute arbitrary code remotely.
- Cause: The vulnerability occurred in the way SMBv3 handled compressed SMB packets. By sending specially crafted packets to a vulnerable server, an attacker could trigger an out-of-bounds write, overwriting critical memory locations. This could allow the attacker to execute arbitrary code with SYSTEM-level privileges on the affected server.
- Impact: The vulnerability was critical because it could be exploited remotely without any user interaction, making it an attractive target for ransomware operators and other cybercriminals. The flaw affected all versions of Windows 10 and Windows Server 2019, creating a widespread risk for enterprises that relied on SMB for file sharing and network communication.
- Mitigation: Microsoft quickly released a patch to address the issue, but prior to this, attackers could exploit the vulnerability using worms to propagate the attack across networks. This was particularly concerning for organisations with large enterprise networks.
- Lessons Learned: The incident emphasised the importance of security patches and rapid response in mitigating vulnerabilities that affect core network protocols. Additionally, it underscored the need for developers to rigorously test and validate memory operations in protocols used in production environments.
3. Apple iOS 14 (CVE-2020-9995)
Apple’s iOS 14, released in 2020, contained an out-of-bounds write vulnerability (CVE-2020-9995) in the kernel, the core of its operating system. This vulnerability could potentially allow an attacker to execute arbitrary code with kernel privileges.
- Cause: The issue was caused by improper validation of memory accesses during certain operations, specifically related to kernel handling of network protocols. An attacker who successfully exploited the vulnerability could write data outside the bounds of allocated memory, potentially leading to code execution in the kernel.
- Impact: Exploiting this flaw could lead to a complete compromise of the device’s security, as attackers could gain root privileges, bypassing the security model enforced by the iOS operating system. Such access would allow attackers to install malicious software, access sensitive data, or remotely control the device.
- Mitigation: Apple patched the vulnerability in iOS 14.0.1, following the discovery by a security researcher. However, before the patch, the vulnerability could have been used to bypass the device’s security measures and compromise the integrity of iOS-based devices.
- Lessons Learned: The iOS incident served as a reminder of how critical it is to validate memory operations thoroughly, especially at the kernel level. Any failure in bounds checking at this level could expose the entire device to attack. It also demonstrated the importance of keeping software up to date with the latest security patches.
4. Cisco ASA (CVE-2018-0296)
In 2018, Cisco discovered a vulnerability in the Adaptive Security Appliance (ASA) software and Firepower Threat Defence (FTD) software, tracked as CVE-2018-0296. This vulnerability allowed attackers to exploit an out-of-bounds write flaw in the SSL VPN feature, potentially resulting in remote code execution.
- Cause: The vulnerability was caused by improper input validation during the parsing of SSL VPN requests. By sending specially crafted requests to a vulnerable ASA or FTD device, an attacker could trigger an out-of-bounds write operation, leading to a crash or, in some cases, arbitrary code execution.
- Impact: Given that the ASA devices are commonly used in enterprise environments to secure VPN traffic, this vulnerability posed a significant risk to organisations relying on these devices for secure remote access. Successful exploitation could allow attackers to gain control of the affected device, potentially leading to further network penetration.
- Mitigation: Cisco quickly issued a patch to address the vulnerability and recommended that users of affected products disable SSL VPN access until the patch could be applied.
- Lessons Learned: The Cisco ASA incident demonstrated the risks of allowing unauthenticated remote access to critical network infrastructure. It highlighted the need for strong input validation and the importance of timely security patches for network appliances, especially when they are exposed to the internet.
5. Android Bluetooth (CVE-2020-0022)
In 2020, a vulnerability in Android’s Bluetooth implementation was discovered, identified as CVE-2020-0022. This out-of-bounds write flaw could allow attackers within Bluetooth range to execute arbitrary code on the device by sending maliciously crafted Bluetooth packets.
- Cause: The flaw was caused by insufficient bounds checking when processing incoming Bluetooth data packets. An attacker who was in close proximity to the device could send specially crafted packets, which would result in the device writing data outside of allocated memory, potentially leading to arbitrary code execution.
- Impact: This vulnerability affected millions of Android devices globally, and because the attack required no user interaction, it posed a serious risk. Exploiting this vulnerability could allow attackers to gain remote control over devices, steal data, or use the device for further malicious activity.
- Mitigation: Google patched the vulnerability in its Android security updates, but it was a reminder of the importance of securing wireless communication protocols that many devices rely on.
- Lessons Learned: The Bluetooth vulnerability underscored the risks of insecure wireless protocols, particularly when memory management is not properly validated. It also highlighted the importance of addressing vulnerabilities in widely used communication protocols such as Bluetooth.
The real-world incidents outlined above show just how devastating out-of-bounds write vulnerabilities (CWE-787) can be. Whether through remote code execution, privilege escalation, or data corruption, these vulnerabilities can have far-reaching consequences for organisations of all sizes. From critical infrastructure like Cisco’s ASA devices to widely used consumer devices like Apple iOS and Android phones, the potential for exploitation is vast.
For software developers and architects, the key takeaway is the importance of rigorous memory management, thorough input validation, and the proactive use of security tools to prevent out-of-bounds writes. Whether it’s through static and dynamic analysis, code reviews, or automated testing, developers must adopt a holistic approach to secure coding practices to minimise the risk of introducing such vulnerabilities into production software.
For businesses, understanding the real-world impact of such vulnerabilities is crucial. The financial, reputational, and operational consequences of a breach due to an out-of-bounds write vulnerability are significant, and investing in secure development practices can protect not only your systems but your customers and stakeholders as well.
Final Thoughts
Out-of-bounds write vulnerabilities (CWE-787) are among the most dangerous weaknesses in software development. If left unchecked, these vulnerabilities can have significant repercussions, including data corruption, service outages, and, in the worst cases, remote code execution.
By understanding the causes of these vulnerabilities and implementing robust mitigation strategies—such as input validation, safe memory management, static and dynamic analysis, and leveraging compiler security features—software developers and architects can build secure, reliable applications that stand up to the evolving landscape of cyber threats.
For C-suite executives, the importance of investing in secure software development practices cannot be overstated. Addressing vulnerabilities like out-of-bounds writes proactively can protect your business from reputational damage, financial losses, and costly security breaches.

The key takeaway: proactively identify and mitigate out-of-bounds write vulnerabilities to safeguard your organisation’s data, reputation, and bottom line.