CWE-404: Improper Resource Shutdown or Release
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
The product does not release or incorrectly releases a resource before it is made available for re-use.
扩展描述
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.
常见后果
影响范围: Availability Other
技术影响: DoS: Resource Consumption (Other) Varies by Context
说明: 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
技术影响: Read Application Data
说明: When a resource containing sensitive information is not correctly shutdown, it may expose the sensitive data in a subsequent allocation.
潜在缓解措施
阶段: Requirements
策略: Language Selection
阶段: 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.
阶段: Implementation
描述: Memory should be allocated/freed using matching functions such as malloc/free, new/delete, and new[]/delete[].
阶段: Implementation
描述: When releasing a complex object or structure, ensure that you properly dispose of all of its member components, not just the object itself.
检测方法
方法: Automated Dynamic Analysis
有效性: Moderate
方法: Manual Dynamic Analysis
Identify error conditions that are not likely to occur during normal usage and trigger them. For example, run the product 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.
方法: Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
有效性: High
观察示例
参考: 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
Chain: Return values of file/socket operations are not checked (CWE-252), allowing resultant consumption of file descriptors (CWE-772).
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| PLOVER | - | Improper resource shutdown or release | - |
| 7 Pernicious Kingdoms | - | Unreleased Resource | - |
| OWASP Top Ten 2004 | A9 | Denial of Service | CWE More Specific |
| CERT C Secure Coding | FIO42-C | Close files when they are no longer needed | CWE More Abstract |
| CERT C Secure Coding | MEM31-C | Free dynamically allocated memory when no longer needed | CWE More Abstract |
| The CERT Oracle Secure Coding Standard for Java (2011) | FIO04-J | Release resources when they are no longer needed | - |
| Software Fault Patterns | SFP14 | Failure to release resource | - |
关键信息
CWE ID: CWE-404
抽象级别: Class
结构: Simple
状态: Draft
利用可能性: Medium