CWE-825 无效指针解引用

Expired Pointer Dereference

结构: Simple

Abstraction: Base

状态: Incomplete

被利用可能性: unkown


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


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.


  • cwe_Nature: ChildOf cwe_CWE_ID: 119 cwe_View_ID: 1000 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 119 cwe_View_ID: 699 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 672 cwe_View_ID: 1000

  • cwe_Nature: ChildOf cwe_CWE_ID: 672 cwe_View_ID: 699

  • cwe_Nature: CanPrecede cwe_CWE_ID: 125 cwe_View_ID: 1000

  • cwe_Nature: CanPrecede cwe_CWE_ID: 787 cwe_View_ID: 1000


范围 影响 注释
Confidentiality 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.
Availability DoS: Crash, Exit, or 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.
['Integrity', 'Confidentiality', 'Availability'] 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.


Architecture and Design


Choose a language that provides automatic memory management.



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.


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

bad C

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.

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

bad C

char ptr = (char)malloc (SIZE);
if (abrt) {

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.


标识 说明 链接
CVE-2008-5013 access of expired memory address leads to arbitrary code execution
CVE-2010-3257 stale pointer issue leads to denial of service and possibly other consequences
CVE-2007-1211 read of value at an offset into a structure after the offset is no longer valid


Maintenance 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. Terminology 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. Research Gap 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.