1756
Manual Static Analysis - Source Code
According to SOAR, the following detection techniques may be useful: Cost effective for partial
coverage: Focused Manual Spotcheck - Focused manual analysis of source Manual Source
Code Review (not inspections)
Effectiveness = SOAR Partial
Automated Static Analysis - Source Code
According to SOAR, the following detection techniques may be useful: Highly cost effective:
Context-configured Source Code Weakness Analyzer
Effectiveness = High
Architecture or Design Review
According to SOAR, the following detection techniques may be useful: Highly cost effective:
Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)
Effectiveness = High
Demonstrative Examples
Example 1:
In this example a mistake exists in the code where the exit condition contained in flg is never
called. This results in the function calling itself over and over again until the stack is exhausted.
Example Language: C (Bad)
void do_something_recursive (int flg)
{
... // Do some real work here, but the value of flg is unmodified
if (flg) { do_something_recursive (flg); } // flg is never modified so it is always TRUE - this call will continue until the stack
explodes
}
int flag = 1; // Set to TRUE
do_something_recursive (flag);
Note that the only difference between the Good and Bad examples is that the recursion flag will
change value and cause the recursive call to return.
Example Language: C (Good)
void do_something_recursive (int flg)
{
... // Do some real work here
// Modify value of flg on done condition
if (flg) { do_something_recursive (flg); } // returns when flg changes to 0
}
int flag = 1; // Set to TRUE
do_something_recursive (flag);
Example 2:
For this example, the method isReorderNeeded is part of a bookstore application that determines if
a particular book needs to be reordered based on the current inventory count and the rate at which
the book is being sold.
Example Language: Java (Bad)
public boolean isReorderNeeded(String bookISBN, int rateSold) {
boolean isReorder = false;
int minimumCount = 10;
int days = 0;
// get inventory count for book
int inventoryCount = inventory.getIventoryCount(bookISBN);
CWE Version 4.14
CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop')
CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop')