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-825: Expired Pointer Dereference

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

Description Summary

The program dereferences a pointer that contains a location for memory that was previously valid, but is no longer valid.

Extended Description

When a program 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 program 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.

+ Alternate Terms
Dangling pointer
+ Terminology Notes

Many weaknesses related to pointer dereferences fall under the general term of "memory corruption" or "memory safety." As of September 2010, there is no commonly-used terminology that covers the lower-level variants.

+ Common Consequences

Technical Impact: Read memory

If the expired pointer is used in a read operation, an attacker might be able to control data read in by the application.


Technical Impact: DoS: crash / exit / restart

If the expired pointer references a memory location that is not accessible to the program, or points to a location that is "malformed" (such as NULL) or larger than expected by a read or write operation, then a crash may occur.


Technical Impact: Execute unauthorized code or commands

If the expired pointer is used in a function call, or points to unexpected data in a write operation, then code execution may be possible.

+ Demonstrative Examples

Example 1

The following code shows a simple example of a use after free error:

(Bad Code)
Example Language:
char* ptr = (char*)malloc (SIZE);
if (err) {
abrt = 1;
if (abrt) {
logError("operation aborted before commit", ptr);

When an error occurs, the pointer is immediately freed. However, this pointer is later incorrectly used in the logError function.

Example 2

The following code shows a simple example of a double free error:

(Bad Code)
Example Language:
char* ptr = (char*)malloc (SIZE);
if (abrt) {

Double free vulnerabilities have two common (and sometimes overlapping) causes:

  • Error conditions and other exceptional circumstances

  • Confusion over which part of the program is responsible for freeing the memory

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.

+ Observed Examples
access of expired memory address leads to arbitrary code execution
stale pointer issue leads to denial of service and possibly other consequences
read of value at an offset into a structure after the offset is no longer valid
+ Potential Mitigations

Phase: Architecture and Design

Choose a language that provides automatic memory management.

Phase: Implementation

When freeing pointers, be sure to set them to NULL once they are freed. However, the utilization of multiple or complex data structures may lower the usefulness of this strategy.

+ 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
ChildOfCategoryCategory465Pointer Issues
Development Concepts699
ChildOfWeakness BaseWeakness Base672Operation on a Resource after Expiration or Release
Development Concepts699
Research Concepts1000
ChildOfCategoryCategory8672011 Top 25 - Weaknesses On the Cusp
Weaknesses in the 2011 CWE/SANS Top 25 Most Dangerous Software Errors (primary)900
CanPrecedeWeakness BaseWeakness Base125Out-of-bounds Read
Research Concepts1000
CanPrecedeWeakness BaseWeakness Base787Out-of-bounds Write
Research Concepts1000
ParentOfWeakness VariantWeakness Variant415Double Free
Research Concepts (primary)1000
ParentOfWeakness BaseWeakness Base416Use After Free
Research Concepts (primary)1000
MemberOfViewView884CWE Cross-section
CWE Cross-section (primary)884
CanFollowWeakness BaseWeakness Base562Return of Stack Variable Address
Research Concepts1000
+ Research Gaps

Under-studied and probably under-reported as of September 2010. This weakness has been reported in high-visibility software, but applied vulnerability researchers have only been investigating it since approximately 2008, and there are only a few public reports. Few reports identify weaknesses at such a low level, which makes it more difficult to find and study real-world code examples.

+ Maintenance Notes

There are close relationships between incorrect pointer dereferences and other weaknesses related to buffer operations. There may not be sufficient community agreement regarding these relationships. Further study is needed to determine when these relationships are chains, composites, perspective/layering, or other types of relationships. As of September 2010, most of the relationships are being captured as chains.

+ Content History
Submission DateSubmitterOrganizationSource
2010-09-22MITREInternal CWE Team
Modification DateModifierOrganizationSource
2011-06-27CWE Content TeamMITREInternal
updated Demonstrative_Examples, Potential_Mitigations, Relationships
2012-05-11CWE Content TeamMITREInternal
updated Demonstrative_Examples, Relationships
2013-02-21CWE Content TeamMITREInternal
updated Alternate_Terms

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