CWE-126: Buffer Over-readWeakness ID: 126 Vulnerability Mapping:
ALLOWEDThis CWE ID may be used to map to real-world vulnerabilities Abstraction: VariantVariant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource. |
Description The product reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations after the targeted buffer. Extended Description This typically occurs when the pointer or its index is incremented 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 exposure of sensitive information or possibly a crash. Common Consequences This table specifies different individual consequences associated with the weakness. The Scope identifies the application security area that is violated, while the Impact describes the negative technical impact that arises if an adversary succeeds in exploiting this weakness. The Likelihood provides information about how likely the specific consequence is expected to be seen relative to the other consequences in the list. For example, there may be high likelihood that a weakness will be exploited to achieve a certain impact, but a low likelihood that it will be exploited to achieve a different impact.Scope | Impact | Likelihood |
---|
Confidentiality
| Technical Impact: Read Memory | | Confidentiality
| Technical Impact: Bypass Protection Mechanism By reading out-of-bounds memory, an attacker might be able to get secret values, such as memory addresses, which can be bypass protection mechanisms such as ASLR in order to improve the reliability and likelihood of exploiting a separate weakness to achieve code execution instead of just denial of service. | |
Relationships This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to similar items that may exist at higher and lower levels of abstraction. In addition, relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user may want to explore. Relevant to the view "Research Concepts" (CWE-1000) Nature | Type | ID | Name |
---|
ChildOf | Base - a weakness
that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 125 | Out-of-bounds Read | ChildOf | Base - a weakness
that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 788 | Access of Memory Location After End of Buffer | CanFollow | Base - a weakness
that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 170 | Improper Null Termination |
Modes Of Introduction The different Modes of Introduction provide information about how and when this weakness may be introduced. The Phase identifies a point in the life cycle at which introduction may occur, while the Note provides a typical scenario related to introduction during the given phase. Demonstrative Examples Example 1 In the following C/C++ example the method processMessageFromSocket() will get a message from a socket, placed into a buffer, and will parse the contents of the buffer into a structure that contains the message length and the message body. A for loop is used to copy the message body into a local character string which will be passed to another method for processing. (bad code) Example Language: C
int processMessageFromSocket(int socket) {
int success;
char buffer[BUFFER_SIZE]; char message[MESSAGE_SIZE];
// get message from socket and store into buffer
//Ignoring possibliity that buffer > BUFFER_SIZE
if (getMessage(socket, buffer, BUFFER_SIZE) > 0) {
// place contents of the buffer into message structure
ExMessage *msg = recastBuffer(buffer);
// copy message body into string for processing
int index; for (index = 0; index < msg->msgLength; index++) { message[index] = msg->msgBody[index]; } message[index] = '\0';
// process message
success = processMessage(message);
} return success;
}
However, the message length variable from the structure is used as the condition for ending the for loop without validating that the message length variable accurately reflects the length of the message body (CWE-606). This can result in a buffer over-read (CWE-125) by reading from memory beyond the bounds of the buffer if the message length variable indicates a length that is longer than the size of a message body (CWE-130). Example 2 The following C/C++ example demonstrates a buffer over-read due to a missing NULL terminator. The main method of a pattern matching utility that looks for a specific pattern within a specific file uses the string strncopy() method to copy the command line user input file name and pattern to the Filename and Pattern character arrays respectively. (bad code) Example Language: C
int main(int argc, char **argv) {
char Filename[256]; char Pattern[32];
/* Validate number of parameters and ensure valid content */
...
/* copy filename parameter to variable, may cause off-by-one overflow */
strncpy(Filename, argv[1], sizeof(Filename));
/* copy pattern parameter to variable, may cause off-by-one overflow */
strncpy(Pattern, argv[2], sizeof(Pattern));
printf("Searching file: %s for the pattern: %s\n", Filename, Pattern); Scan_File(Filename, Pattern); }
However, the code do not take into account that strncpy() will not add a NULL terminator when the source buffer is equal in length of longer than that provide size attribute. Therefore if a user enters a filename or pattern that are the same size as (or larger than) their respective character arrays, a NULL terminator will not be added (CWE-170) which leads to the printf() read beyond the expected end of the Filename and Pattern buffers. To fix this problem, be sure to subtract 1 from the sizeof() call to allow room for the null byte to be added. (good code) Example Language: C
/* copy filename parameter to variable, no off-by-one overflow */
strncpy(Filename, argv[2], sizeof(Filename)-1); Filename[255]='\0';
/* copy pattern parameter to variable, no off-by-one overflow */
strncpy(Pattern, argv[3], sizeof(Pattern)-1); Pattern[31]='\0';
Observed Examples Reference | Description |
| Text editor has out-of-bounds read past end of line while indenting C code |
| Chain: "Heartbleed" bug receives an inconsistent length parameter ( CWE-130) enabling an out-of-bounds read ( CWE-126), returning memory that could include private cryptographic keys and other sensitive data. |
| Chain: product does not handle when an input string is not NULL terminated, leading to buffer over-read or heap-based buffer overflow. |
Weakness Ordinalities Ordinality | Description |
Primary | (where the weakness exists independent of other weaknesses) |
Detection Methods
Automated Static Analysis Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.) |
Memberships This MemberOf Relationships table shows additional CWE Categories and Views that reference this weakness as a member. This information is often useful in understanding where a weakness fits within the context of external information sources. Vulnerability Mapping Notes Usage: ALLOWED (this CWE ID could be used to map to real-world vulnerabilities) | Reason: Acceptable-Use | Rationale: This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities. | Comments: Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction. |
Notes Relationship These problems may be resultant from missing sentinel values ( CWE-463) or trusting a user-influenced input length variable. Taxonomy Mappings Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
PLOVER | | | Buffer over-read |
Software Fault Patterns | SFP8 | | Faulty Buffer Access |
References
[REF-1034] Raoul Strackx, Yves Younan, Pieter Philippaerts, Frank Piessens, Sven Lachmund
and Thomas Walter. "Breaking the memory secrecy assumption". ACM. 2009-03-31.
< https://dl.acm.org/doi/10.1145/1519144.1519145>. URL validated: 2023-04-07. |
|
[REF-44] Michael Howard, David LeBlanc
and John Viega. "24 Deadly Sins of Software Security". "Sin 5: Buffer Overruns." Page 89. McGraw-Hill. 2010.
|
Content History Submissions |
---|
Submission Date | Submitter | Organization |
---|
2006-07-19 (CWE Draft 3, 2006-07-19) | PLOVER | | | Modifications |
---|
Modification Date | Modifier | Organization |
---|
2008-09-08 | CWE Content Team | MITRE | updated Applicable_Platforms, Relationships, Taxonomy_Mappings, Weakness_Ordinalities | 2009-10-29 | CWE Content Team | MITRE | updated Description, Relationship_Notes, Relationships | 2011-03-29 | CWE Content Team | MITRE | updated Demonstrative_Examples | 2011-06-01 | CWE Content Team | MITRE | updated Common_Consequences | 2012-05-11 | CWE Content Team | MITRE | updated Demonstrative_Examples, Relationships | 2014-06-23 | CWE Content Team | MITRE | updated Observed_Examples | 2014-07-30 | CWE Content Team | MITRE | updated Relationships, Taxonomy_Mappings | 2017-11-08 | CWE Content Team | MITRE | updated Causal_Nature, Demonstrative_Examples | 2018-03-27 | CWE Content Team | MITRE | updated Demonstrative_Examples | 2019-09-19 | CWE Content Team | MITRE | updated Common_Consequences, References | 2020-02-24 | CWE Content Team | MITRE | updated Relationships | 2020-06-25 | CWE Content Team | MITRE | updated Demonstrative_Examples | 2023-01-31 | CWE Content Team | MITRE | updated Description | 2023-04-27 | CWE Content Team | MITRE | updated Detection_Factors, References, Relationships | 2023-06-29 | CWE Content Team | MITRE | updated Mapping_Notes | 2023-10-26 | CWE Content Team | MITRE | updated Observed_Examples |
More information is available — Please edit the custom filter or select a different filter.
|