Description
The product reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations after the targeted buffer.
Potential Impact
Confidentiality
Read Memory
Confidentiality
Bypass Protection Mechanism
Availability, Integrity
DoS: Crash, Exit, or Restart
Demonstrative Examples
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;
}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);}/* 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';Detection Methods
- Automated Static Analysis High — 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 sea
- Automated Dynamic Analysis Moderate — Use tools that are integrated during compilation to insert runtime error-checking mechanisms related to memory safety errors, such as AddressSanitizer (ASan) for C/C++ [REF-1518].
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2022-1733 | Text editor has out-of-bounds read past end of line while indenting C code |
| CVE-2014-0160 | 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 |
| CVE-2009-2523 | Chain: product does not handle when an input string is not NULL terminated, leading to buffer over-read or heap-based buffer overflow. |
Related Weaknesses
Taxonomy Mappings
- PLOVER: — Buffer over-read
- Software Fault Patterns: SFP8 — Faulty Buffer Access
Frequently Asked Questions
What is CWE-126?
CWE-126 (Buffer Over-read) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Variant-level weakness. The product reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations after the targeted buffer.
How can CWE-126 be exploited?
Attackers can exploit CWE-126 (Buffer Over-read) to read memory. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-126?
Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.
What is the severity of CWE-126?
CWE-126 is classified as a Variant-level weakness (Low-Medium abstraction). It has been observed in 3 real-world CVEs.