AUTOSAR C++14 Rule A5-6-1
The right hand operand of the integer division or remainder operators shall not be equal to zero
Description
Rule Definition
The right hand operand of the integer division or remainder operators shall not be equal to zero.
Rationale
If the numerator is the minimum possible value and the denominator is
-1
, your division operation overflows because the result cannot be represented by the current variable size.If the denominator is zero, your division operation fails possibly causing your program to crash.
These risks can be used to execute arbitrary code. This code is usually outside the scope of a program's implicit security policy.
If the second remainder operand is zero, your remainder operation fails, causing your program to crash.
If the second remainder operand is
-1
, your remainder operation can overflow if the remainder operation is implemented based on the division operation that can overflow.If one of the operands is negative, the operation result is uncertain. For C89, the modulo operation is not standardized, so the result from negative operands is implementation-defined.
These risks can be exploited by attackers to gain access to your program or the target in general.
Polyspace Implementation
The checker raises a defect when:
The denominator of a division or modulo operation can be a zero-valued integer.
There are division operations where one or both of the integer operands is from an unsecure source.
There are modulo operations with one or more tainted operands.
Extend Checker
Extend this checker to check for defects caused by specific values and external inputs. For instance:
A default Bug Finder analysis might not raise a defect when the input values are unknown and only a subset of inputs can cause an issue. To check for defects caused by specific system input values, run a stricter Bug Finder analysis. See Extend Bug Finder Checkers to Find Defects from Specific System Input Values.
By default, Polyspace® assumes that data from external sources are tainted. See Sources of Tainting in a Polyspace Analysis. To consider any data that does not originate in the current scope of Polyspace analysis as tainted, use the command line option
-consider-analysis-perimeter-as-trust-boundary
.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Expressions |
Category: Required, Automated |
Version History
Introduced in R2019a