CWE-825: Expired Pointer Dereference
Description
The product dereferences a pointer that contains a location for memory that was previously valid, but is no longer valid.
Submission Date :
Sept. 22, 2010, midnight
Modification Date :
2023-06-29 00:00:00+00:00
Organization :
MITRE
Extended Description
When a product releases memory, but it maintains a pointer to that memory, then the memory might be re-allocated at a later time. If the original pointer is accessed to read or write data, then this could cause the product to read or modify data that is in use by a different function or process. Depending on how the newly-allocated memory is used, this could lead to a denial of service, information exposure, or code execution.
Example - 1
The following code shows a simple example of a use after free error: When an error occurs, the pointer is immediately freed. However, this pointer is later incorrectly used in the logError function.
abrt = 1;free(ptr);
logError("operation aborted before commit", ptr);char* ptr = (char*)malloc (SIZE);if (err) {}...if (abrt) {}
Example - 2
The following code shows a simple example of a double free error: Double free vulnerabilities have two common (and sometimes overlapping) causes: Although some double free vulnerabilities are not much more complicated than the previous example, most are spread out across hundreds of lines of code or even different files. Programmers seem particularly susceptible to freeing global variables more than once.
free(ptr);
char* ptr = (char*)malloc (SIZE);...if (abrt) {}...free(ptr);
Related Weaknesses
This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined to give an overview of the different insight to similar items that may exist at higher and lower levels of abstraction.
CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer
CWE-125: Out-of-bounds Read
CWE-415: Double Free
CWE-416: Use After Free
CWE-562: Return of Stack Variable Address
CWE-672: Operation on a Resource after Expiration or Release
CWE-787: Out-of-bounds Write
Visit http://cwe.mitre.org/ for more details.