结构: Simple
Abstraction: Class
状态: Draft
被利用可能性: unkown
The software uses, accesses, or otherwise operates on a resource after that resource has been expired, released, or revoked.
Language: {'cwe_Class': 'Language-Independent', 'cwe_Prevalence': 'Undetermined'}
Paradigm: {'cwe_Name': 'Mobile', 'cwe_Prevalence': 'Undetermined'}
范围 | 影响 | 注释 |
---|---|---|
['Integrity', 'Confidentiality'] | ['Modify Application Data', 'Read Application Data'] | If a released resource is subsequently reused or reallocated, then an attempt to use the original resource might allow access to sensitive data that is associated with a different user or entity. |
['Other', 'Availability'] | ['Other', 'DoS: Crash, Exit, or Restart'] | When a resource is released it might not be in an expected state, later attempts to access the resource may lead to resultant errors that may lead to a crash. |
The following code shows a simple example of a use after free error:
bad C
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
Double free vulnerabilities have two common (and sometimes overlapping) causes:
None
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.
In the following C/C++ example the method processMessage is used to process a message received in the input array of char arrays. The input message array contains two char arrays: the first is the length of the message and the second is the body of the message. The length of the message is retrieved and used to allocate enough memory for a local char array, messageBody, to be created for the message body. The messageBody is processed in the method processMessageBody that will return an error if an error occurs while processing. If an error occurs then the return result variable is set to indicate an error and the messageBody char array memory is released using the method free and an error message is sent to the logError method.
bad C
However, the call to the method logError includes the messageBody after the memory for messageBody has been released using the free method. This can cause unexpected results and may lead to system crashes. A variable should never be used after its memory resources have been released.
good C
标识 | 说明 | 链接 |
---|---|---|
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
Software Fault Patterns | SFP15 | Faulty Resource Use | |
CERT C Secure Coding | FIO46-C | CWE More Abstract | Do not access a closed file |
CERT C Secure Coding | MEM30-C | CWE More Abstract | Do not access freed memory |
OMG ASCSM | ASCSM-CWE-672 |