CWE-571 表达式永真

admin 2021年11月4日23:16:12评论72 views字数 1903阅读6分20秒阅读模式

CWE-571 表达式永真

Expression is Always True

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: unkown

基本描述

The software contains an expression that will always evaluate to true.

相关缺陷

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

  • cwe_Nature: CanPrecede cwe_CWE_ID: 561 cwe_View_ID: 1000

  • cwe_Nature: CanPrecede cwe_CWE_ID: 561 cwe_View_ID: 699

适用平台

Language: {'cwe_Class': 'Language-Independent', 'cwe_Prevalence': 'Undetermined'}

常见的影响

范围 影响 注释
Other ['Quality Degradation', 'Varies by Context']

可能的缓解方案

Testing

策略:

Use Static Analysis tools to spot such conditions.

示例代码

In the following Java example the updateInventory() method used within an e-business product ordering/inventory application will check if the input product number is in the store or in the warehouse. If the product is found, the method will update the store or warehouse database as well as the aggregate product database. If the product is not found, the method intends to do some special processing without updating any database.

bad Java


public void updateInventory(String productNumber) {

boolean isProductAvailable = false;
boolean isDelayed = false;

if (productInStore(productNumber)) {

isProductAvailable = true;
updateInStoreDatabase(productNumber);

}
else if (productInWarehouse(productNumber)) {

isProductAvailable = true;
updateInWarehouseDatabase(productNumber);

}
else {

isProductAvailable = true;

}

if ( isProductAvailable ) {

updateProductDatabase(productNumber);

}
else if ( isDelayed ) {


/ Warn customer about delay before order processing /

...

}

}

However, the method never sets the isDelayed variable and instead will always update the isProductAvailable variable to true. The result is that the predicate testing the isProductAvailable boolean will always evaluate to true and therefore always update the product database. Further, since the isDelayed variable is initialized to false and never changed, the expression always evaluates to false and the customer will never be warned of a delay on their product.

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
CERT C Secure Coding MSC00-C Compile cleanly at high warning levels
Software Fault Patterns SFP1 Glitch in computation

文章来源于互联网:scap中文网

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年11月4日23:16:12
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-571 表达式永真http://cn-sec.com/archives/613102.html

发表评论

匿名网友 填写信息