CWE-571: Expression is Always True

Description

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

Submission Date :

Dec. 15, 2006, midnight

Modification Date :

2023-06-29 00:00:00+00:00

Organization :

MITRE
Example Vulnerable Codes

Example - 1

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.




isProductAvailable = true;updateInStoreDatabase(productNumber);

isProductAvailable = true;updateInWarehouseDatabase(productNumber);
isProductAvailable = true;
updateProductDatabase(productNumber);

// /* Warn customer about delay before order processing */// 
...boolean isProductAvailable = false;boolean isDelayed = false;if (productInStore(productNumber)) {}else if (productInWarehouse(productNumber)) {}else {}if ( isProductAvailable ) {}else if ( isDelayed ) {}public void updateInventory(String productNumber) {}

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.

Related Weaknesses

This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined to give an overview of the different insight to similar items that may exist at higher and lower levels of abstraction.

Visit http://cwe.mitre.org/ for more details.