Common Weakness Enumeration

A Community-Developed List of Software Weakness Types

CWE/SANS Top 25 Most Dangerous Software Errors
Home > CWE List > CWE- Individual Dictionary Definition (2.11)  

CWE-787: Out-of-bounds Write

Weakness ID: 787
Abstraction: Base
Status: Incomplete
Presentation Filter:
+ Description

Description Summary

The software writes data past the end, or before the beginning, of the intended buffer.

Extended Description

This typically occurs when the pointer or its index is incremented or decremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in corruption of sensitive information, a crash, or code execution among other things.

+ Common Consequences

Technical Impact: Modify memory; DoS: crash / exit / restart; Execute unauthorized code or commands

+ Demonstrative Examples

Example 1

The following code attempts to save four different identification numbers into an array.

(Bad Code)
Example Language:
int id_sequence[3];

/* Populate the id array. */

id_sequence[0] = 123;
id_sequence[1] = 234;
id_sequence[2] = 345;
id_sequence[3] = 456;

Example 2

In the following example, it is possible to request that memcpy move a much larger segment of memory than assumed:

(Bad Code)
Example Language:
int returnChunkSize(void *) {
/* if chunk info is valid, return the size of usable memory,
* else, return -1 to indicate an error
int main() {
memcpy(destBuf, srcBuf, (returnChunkSize(destBuf)-1));

If returnChunkSize() happens to encounter an error it will return -1. Notice that the return value is not checked before the memcpy operation (CWE-252), so -1 can be passed as the size argument to memcpy() (CWE-805). Because memcpy() assumes that the value is unsigned, it will be interpreted as MAXINT-1 (CWE-195), and therefore will copy far more memory than is likely available to the destination buffer (CWE-787, CWE-788).

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfWeakness ClassWeakness Class119Improper Restriction of Operations within the Bounds of a Memory Buffer
Development Concepts (primary)699
Research Concepts (primary)1000
Weaknesses for Simplified Mapping of Published Vulnerabilities (primary)1003
ParentOfWeakness VariantWeakness Variant121Stack-based Buffer Overflow
Development Concepts699
Research Concepts1000
ParentOfWeakness VariantWeakness Variant122Heap-based Buffer Overflow
Development Concepts699
Research Concepts1000
ParentOfWeakness BaseWeakness Base124Buffer Underwrite ('Buffer Underflow')
Development Concepts699
Research Concepts1000
CanFollowWeakness BaseWeakness Base822Untrusted Pointer Dereference
Research Concepts1000
CanFollowWeakness BaseWeakness Base823Use of Out-of-range Pointer Offset
Research Concepts1000
CanFollowWeakness BaseWeakness Base824Access of Uninitialized Pointer
Research Concepts1000
CanFollowWeakness BaseWeakness Base825Expired Pointer Dereference
Research Concepts1000
+ Content History
Submission DateSubmitterOrganizationSource
2009-10-21MITREInternal CWE Team
Modification DateModifierOrganizationSource
2010-02-16CWE Content TeamMITREInternal
updated Demonstrative_Examples
2010-09-27CWE Content TeamMITREInternal
updated Relationships
2011-06-01CWE Content TeamMITREInternal
updated Common_Consequences
2014-06-23CWE Content TeamMITREInternal
updated Demonstrative_Examples
2015-12-07CWE Content TeamMITREInternal
updated Relationships

More information is available — Please select a different filter.
Page Last Updated: May 05, 2017