CWE-571: Expression is Always True

Export to Word

Description

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

Extended Description

N/A


ThreatScore

Threat Mapped score: 0.0

Industry: Finiancial

Threat priority: Unclassified


Observed Examples (CVEs)

Related Attack Patterns (CAPEC)

N/A


Attack TTPs

N/A

Modes of Introduction

Phase Note
Implementation N/A

Common Consequences

Potential Mitigations

Applicable Platforms


Demonstrative Examples

Intro: 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.

Body: 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.

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 */ ... } }

Notes

← Back to CWE list