结构: Simple
Abstraction: Base
状态: Draft
被利用可能性: Medium
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.
cwe_Nature: ChildOf cwe_CWE_ID: 682 cwe_View_ID: 1000 cwe_Ordinal: Primary
cwe_Nature: ChildOf cwe_CWE_ID: 682 cwe_View_ID: 1003 cwe_Ordinal: Primary
cwe_Nature: ChildOf cwe_CWE_ID: 682 cwe_View_ID: 699 cwe_Ordinal: Primary
范围 | 影响 | 注释 |
---|---|---|
Availability | DoS: Crash, Exit, or Restart | A Divide by Zero results in a crash. |
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.
bad Java
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.
good
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.
bad C
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.
good
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.
bad C#
The method can be modified to raise, catch and handle the DivideByZeroException if the input value used as the denominator is zero.
good
标识 | 说明 | 链接 |
---|---|---|
CVE-2007-3268 | Invalid size value leads to divide by zero. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-3268 |
CVE-2007-2723 | "Empty" content triggers divide by zero. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-2723 |
CVE-2007-2237 | Height value of 0 triggers divide by zero. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-2237 |
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
OWASP Top Ten 2004 | A9 | CWE More Specific | Denial of Service |
CERT C Secure Coding | FLP03-C | Detect and handle floating point errors | |
CERT C Secure Coding | INT33-C | Exact | Ensure that division and remainder operations do not result in divide-by-zero errors |
The CERT Oracle Secure Coding Standard for Java (2011) | NUM02-J | Ensure that division and modulo operations do not result in divide-by-zero errors | |
Software Fault Patterns | SFP1 | Glitch in computation |