CWE-129: Improper Validation of Array Index
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
The product uses untrusted input when calculating or using an array index, but the product does not validate or incorrectly validates the index to ensure the index references a valid position within the array.
常见后果
影响范围: Integrity Availability
技术影响: DoS: Crash, Exit, or Restart
说明: Use of an index that is outside the bounds of an array will very likely result in the corruption of relevant memory and perhaps instructions, leading to a crash, if the values are outside of the valid memory area.
影响范围: Integrity
技术影响: Modify Memory
说明: If the memory corrupted is data, rather than instructions, the system will continue to function with improper values.
影响范围: Confidentiality Integrity
技术影响: Modify Memory Read Memory
说明: Use of an index that is outside the bounds of an array can also trigger out-of-bounds read or write operations, or operations on the wrong objects; i.e., "buffer overflows" are not always the result. This may result in the exposure or modification of sensitive data.
影响范围: Integrity Confidentiality Availability
技术影响: Execute Unauthorized Code or Commands
说明: If the memory accessible by the attacker can be effectively controlled, it may be possible to execute arbitrary code, as with a standard buffer overflow and possibly without the use of large inputs if a precise index can be controlled.
影响范围: Integrity Availability Confidentiality
技术影响: DoS: Crash, Exit, or Restart Execute Unauthorized Code or Commands Read Memory Modify Memory
说明: A single fault could allow either an overflow (CWE-788) or underflow (CWE-786) of the array index. What happens next will depend on the type of operation being performed out of bounds, but can expose sensitive information, cause a system crash, or possibly lead to arbitrary code execution.
潜在缓解措施
阶段: Architecture and Design
策略: Input Validation
描述: Use an input validation framework such as Struts or the OWASP ESAPI Validation API. Note that using a framework does not automatically address all input validation problems; be mindful of weaknesses that could arise from misusing the framework itself (CWE-1173).
阶段: Architecture and Design
阶段: Requirements
策略: Language Selection
阶段: Operation Build and Compilation
策略: Environment Hardening
有效性: Defense in Depth
阶段: Operation
策略: Environment Hardening
有效性: Defense in Depth
阶段: Implementation
策略: Input Validation
阶段: Implementation
描述: Be especially careful to validate all input when invoking code that crosses language boundaries, such as from an interpreted language to native code. This could create an unexpected interaction between the language boundaries. Ensure that you are not violating any of the expectations of the language with which you are interfacing. For example, even though Java may not be susceptible to buffer overflows, providing a large argument in a call to native code might trigger an overflow.
阶段: Architecture and Design Operation
策略: Environment Hardening
描述: Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
阶段: Architecture and Design Operation
策略: Sandbox or Jail
有效性: Limited
检测方法
方法: Automated Static Analysis
有效性: High
方法: Automated Dynamic Analysis
This weakness can be detected using 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.
方法: Black Box
Black box methods might not get the needed code coverage within limited time constraints, and a dynamic test might not produce any noticeable side effects even if it is successful.
观察示例
参考: CVE-2005-0369
large ID in packet used as array index
参考: CVE-2001-1009
negative array index as argument to POP LIST command
参考: CVE-2003-0721
Integer signedness error leads to negative array index
参考: CVE-2004-1189
product does not properly track a count and a maximum number, which can lead to resultant array index overflow.
参考: CVE-2007-5756
Chain: device driver for packet-capturing software allows access to an unintended IOCTL with resultant array index error.
参考: CVE-2005-2456
Chain: array index error (CWE-129) leads to deadlock (CWE-833)
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| CLASP | - | Unchecked array indexing | - |
| PLOVER | - | INDEX - Array index overflow | - |
| CERT C Secure Coding | ARR00-C | Understand how arrays work | - |
| CERT C Secure Coding | ARR30-C | Do not form or use out-of-bounds pointers or array subscripts | CWE More Specific |
| CERT C Secure Coding | ARR38-C | Do not add or subtract an integer to a pointer if the resulting value does not refer to a valid array element | - |
| CERT C Secure Coding | INT32-C | Ensure that operations on signed integers do not result in overflow | - |
| SEI CERT Perl Coding Standard | IDS32-PL | Validate any integer that is used as an array index | Imprecise |
| OMG ASCSM | ASCSM-CWE-129 | - | |
| Software Fault Patterns | SFP8 | Faulty Buffer Access | - |