CWE-606 循环条件输入未经检查

Unchecked Input for Loop Condition

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown

基本描述

The product does not properly check inputs that are used for loop conditions, potentially leading to a denial of service because of excessive looping.

相关缺陷

  • cwe_Nature: ChildOf cwe_CWE_ID: 20 cwe_View_ID: 1000 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 20 cwe_View_ID: 699 cwe_Ordinal: Primary

  • cwe_Nature: CanPrecede cwe_CWE_ID: 834 cwe_View_ID: 1000

常见的影响

范围 影响 注释
Availability DoS: Resource Consumption (CPU)

可能的缓解方案

Implementation

策略:

Do not use user-controlled data for loop conditions.

Implementation

策略:

Perform input validation.

示例代码

The following example demonstrates the weakness.

bad C

void iterate(int n){
int i;
for (i = 0; i < n; i++){
foo();
}
}
void iterateFoo()
{
unsigned int num;
scanf("%u",&num);
iterate(num);
}

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
Software Fault Patterns SFP25 Tainted input to variable
OMG ASCSM ASCSM-CWE-606

引用