The product divides a value by zero.
This weakness typically occurs when an unexpected value is provided to the product, or if an error occurs that is not properly detected. It frequently occurs in calculations involving physical dimensions such as size, length, width, and height.
Threat Mapped score: 0.0
Industry: Finiancial
Threat priority: Unclassified
CVE: CVE-2007-3268
Invalid size value leads to divide by zero.
CVE: CVE-2007-2723
"Empty" content triggers divide by zero.
CVE: CVE-2007-2237
Height value of 0 triggers divide by zero.
N/A
N/A
Phase | Note |
---|---|
Implementation | N/A |
Intro: The following Java example contains a function to compute an average but does not validate that the input value used as the denominator is not zero. This will create an exception for attempting to divide by zero. If this error is not handled by Java exception handling, unexpected results can occur.
Body: By validating the input value used as the denominator the following code will ensure that a divide by zero error will not cause unexpected results. The following Java code example will validate the input value, output an error message, and throw an exception.
public int computeAverageResponseTime (int totalTime, int numRequests) { return totalTime / numRequests; }
Intro: The following C/C++ example contains a function that divides two numeric values without verifying that the input value used as the denominator is not zero. This will create an error for attempting to divide by zero, if this error is not caught by the error handling capabilities of the language, unexpected results can occur.
Body: By validating the input value used as the denominator the following code will ensure that a divide by zero error will not cause unexpected results. If the method is called and a zero is passed as the second argument a DivideByZero error will be thrown and should be caught by the calling block with an output message indicating the error.
double divide(double x, double y){ return x/y; }
Intro: The following C# example contains a function that divides two numeric values without verifying that the input value used as the denominator is not zero. This will create an error for attempting to divide by zero, if this error is not caught by the error handling capabilities of the language, unexpected results can occur.
Body: The method can be modified to raise, catch and handle the DivideByZeroException if the input value used as the denominator is zero.
int Division(int x, int y){ return (x / y); }