使用被污染的索引进行数组访问
R2025a来自不安全源的数组索引可能超出数组范围
描述
当您使用从不安全来源获得且未经过验证的索引访问数组时,会发生此缺陷。
风险
索引可能超出有效数组范围。如果受污染的索引超出数组范围,可能会导致:
缓冲区下溢/下写 - 在缓冲区开始之前向内存写入数据。
缓冲区溢出 - 在缓冲区末尾之后向内存中写入数据。
缓冲区读取越界 - 在目标缓冲区末尾之后访问内存。
缓冲区读取不足,或在目标缓冲区开始之前访问内存。
攻击者可以利用无效的读写操作在您的程序中引发问题。
修复
在使用索引访问数组之前,请验证索引值,确保其在数组范围内。
扩展检查项
默认情况下,Polyspace® 假设来自外部源的数据是受污染的。请参阅Sources of Tainting in a Polyspace Analysis。要将当前 Polyspace 分析范围内未产生的数据视为受污染数据,请使用命令行选项 -consider-analysis-perimeter-as-trust-boundary。
示例
结果信息
| 组:被污染的数据 |
| 语言:C | C++ |
| 默认值:关闭 |
命令行语法:TAINTED_ARRAY_INDEX |
| 影响:中 |
版本历史记录
在 R2015b 中推出
另请参阅
Loop bounded with tainted value (TAINTED_LOOP_BOUNDARY) | Pointer dereference with tainted offset (TAINTED_PTR_OFFSET) | Tainted size of variable length array (TAINTED_VLA_SIZE) | 查找缺陷 (-checkers) | -consider-analysis-perimeter-as-trust-boundary
主题
- Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface
- 解释 Polyspace Access Web 界面中的 Bug Finder 结果 (Polyspace Access)
- Address Polyspace Results Through Bug Fixes or Justifications
- 通过 Bug 修复或申述在 Polyspace Access 中处理结果 (Polyspace Access)
- Sources of Tainting in a Polyspace Analysis
- Modify Default Behavior of Bug Finder Checkers