Improper Resource Shutdown or Release |
Weakness ID: 404 (Weakness Base) | Status: Draft |
Description Summary
Extended Description
When a resource is created or allocated, the developer is responsible for properly releasing the resource as well as accounting for all potential paths of expiration or invalidation, such as a set period of time or revocation.
Scope | Effect |
---|---|
Availability | Most unreleased resource issues result in general software reliability problems, but if an attacker can intentionally trigger a resource leak, the attacker might be able to launch a denial of service attack by depleting the resource pool. |
Confidentiality | When a resource containing sensitive information is not correctly shutdown, it may expose the sensitive data in a subsequent allocation. |
Example 1
The following method never closes the file handle it opens. The Finalize() method for StreamReader eventually calls Close(), but there is no guarantee as to how long it will take before the Finalize() method is invoked. In fact, there is no guarantee that Finalize() will ever be invoked. In a busy environment, this can result in the VM using up all of its available file handles.
Example 2
If an exception occurs after establishing the database connection and before the same connection closes, the pool of database connections may become exhausted. If the number of available connections is exceeded, other users cannot access this resource, effectively denying access to the application. Using the following database connection pattern will ensure that all opened connections are closed. The con.close() call should be the first executable statement in the finally block.
Example 3
Under normal conditions the following C# code executes a database query, processes the results returned by the database, and closes the allocated SqlConnection object. But if an exception occurs while executing the SQL or processing the results, the SqlConnection object is not closed. If this happens often enough, the database will run out of available cursors and not be able to execute any more SQL queries.
Example 4
The following C function does not close the file handle it opens if an error occurs. If the process is long-lived, the process can run out of file handles.
Example 5
In this example, the program fails to use matching functions such as malloc/free, new/delete, and new[]/delete[] to allocate/deallocate the resource.
Example 6
In this example, the program calls the delete[] function on non-heap memory.
Reference | Description |
---|---|
CVE-1999-1127 | Does not shut down named pipe connections if malformed data is sent. |
CVE-2001-0830 | Sockets not properly closed when attacker repeatedly connects and disconnects from server. |
CVE-2002-1372 | Return values of file/socket operations not checked, allowing resultant consumption of file descriptors. |
Phase: Requirements Strategy: Language Selection Use a language with features that can automatically mitigate or eliminate resource-shutdown weaknesses. For example, languages such as Java, Ruby, and Lisp perform automatic garbage collection that releases memory for objects that have been deallocated. |
Phase: Implementation It is good practice to be responsible for freeing all resources you allocate and to be consistent with how and where you free memory in a function. If you allocate memory that you intend to free upon completion of the function, you must be sure to free the memory at all exit points for that function including error conditions. |
Phase: Implementation Memory should be allocated/freed using matching functions such as malloc/free, new/delete, and new[]/delete[]. |
Phase: Implementation When releasing a complex object or structure, ensure that you properly dispose of all of its member components, not just the object itself. |
Phase: Testing Use dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results. |
Phase: Testing Stress-test the software by calling it simultaneously from a large number of threads or processes, and look for evidence of any unexpected behavior. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results. |
Phase: Testing Identify error conditions that are not likely to occur during normal usage and trigger them. For example, run the program under low memory conditions, run with insufficient privileges or permissions, interrupt a transaction before it is completed, or disable connectivity to basic network services such as DNS. Monitor the software for any unexpected behavior. If you trigger an unhandled exception or similar error that was discovered and handled by the application's environment, it may still indicate unexpected conditions that were not handled by the application itself. |
Ordinality | Description |
---|---|
Primary | Failing to properly release or shutdown resources can be primary to resource exhaustion, performance, and information confidentiality problems to name a few. |
Resultant | Failing to properly release or shutdown resources can be resultant from improper error handling or insufficient resource tracking. |
Nature | Type | ID | Name | View(s) this relationship pertains to![]() |
---|---|---|---|---|
ChildOf | ![]() | 398 | Indicator of Poor Code Quality | Development Concepts699 Seven Pernicious Kingdoms (primary)700 |
ChildOf | ![]() | 399 | Resource Management Errors | Development Concepts (primary)699 |
ChildOf | ![]() | 664 | Improper Control of a Resource Through its Lifetime | Research Concepts (primary)1000 |
ChildOf | ![]() | 730 | OWASP Top Ten 2004 Category A9 - Denial of Service | Weaknesses in OWASP Top Ten (2004) (primary)711 |
ChildOf | ![]() | 743 | CERT C Secure Coding Section 09 - Input Output (FIO) | Weaknesses Addressed by the CERT C Secure Coding Standard (primary)734 |
ChildOf | ![]() | 752 | 2009 Top 25 - Risky Resource Management | Weaknesses in the 2009 CWE/SANS Top 25 Most Dangerous Programming Errors (primary)750 |
PeerOf | ![]() | 405 | Asymmetric Resource Consumption (Amplification) | Research Concepts1000 |
ParentOf | ![]() | 262 | Not Using Password Aging | Research Concepts (primary)1000 |
ParentOf | ![]() | 263 | Password Aging with Long Expiration | Research Concepts (primary)1000 |
ParentOf | ![]() | 299 | Improper Check for Certificate Revocation | Research Concepts (primary)1000 |
ParentOf | ![]() | 459 | Incomplete Cleanup | Research Concepts (primary)1000 |
ParentOf | ![]() | 568 | finalize() Method Without super.finalize() | Research Concepts (primary)1000 |
ParentOf | ![]() | 619 | Dangling Database Cursor ('Cursor Injection') | Development Concepts (primary)699 Research Concepts (primary)1000 |
ParentOf | ![]() | 763 | Release of Invalid Pointer or Reference | Research Concepts (primary)1000 |
ParentOf | ![]() | 772 | Missing Release of Resource after Effective Lifetime | Research Concepts (primary)1000 |
PeerOf | ![]() | 239 | Failure to Handle Incomplete Element | Research Concepts1000 |
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
PLOVER | Improper resource shutdown or release | ||
7 Pernicious Kingdoms | Unreleased Resource | ||
OWASP Top Ten 2004 | A9 | CWE More Specific | Denial of Service |
CERT C Secure Coding | FIO42-C | Ensure files are properly closed when they are no longer needed |
Submissions | ||||
---|---|---|---|---|
Submission Date | Submitter | Organization | Source | |
PLOVER | Externally Mined | |||
Modifications | ||||
Modification Date | Modifier | Organization | Source | |
2008-07-01 | Eric Dalci | Cigital | External | |
updated Time of Introduction | ||||
2008-08-15 | Veracode | External | ||
Suggested OWASP Top Ten 2004 mapping | ||||
2008-09-08 | CWE Content Team | MITRE | Internal | |
updated Description, Relationships, Other Notes, Taxonomy Mappings | ||||
2008-10-14 | CWE Content Team | MITRE | Internal | |
updated Relationships | ||||
2008-11-24 | CWE Content Team | MITRE | Internal | |
updated Relationships, Taxonomy Mappings | ||||
2009-01-12 | CWE Content Team | MITRE | Internal | |
updated Common Consequences, Likelihood of Exploit, Other Notes, Potential Mitigations, Relationship Notes, Relationships, Weakness Ordinalities | ||||
2009-03-10 | CWE Content Team | MITRE | Internal | |
updated Potential Mitigations | ||||
2009-05-27 | CWE Content Team | MITRE | Internal | |
updated Description, Relationships | ||||
2009-07-27 | CWE Content Team | MITRE | Internal | |
updated Demonstrative Examples, Related Attack Patterns | ||||
2009-10-29 | CWE Content Team | MITRE | Internal | |
updated Other Notes |