...
The isinf
macro tests an input floating point value for infinity. isinf
(x) returns 1 if x is infinity, -1 if x is negative infinity, and 0 otherwise.
...
This can be a problem if an invalid value is entered for val and subsequently used for calculations or as control values. The user could, for example, input the values "INF", "INFINITY", or "NAN" on the command line, which would be parsed by scanf into the floating-point representations of infinity and NaN. All subsequent calculations using these values would be invalid, possibly crashing the program and enabling a DOS attack.
isinf and isnan
Compliant Code Example
The following code first validates the input float before using it. The value is tested to ensure that it is within the acceptable range of MIN_VAL to MAX_VAL (and is therefore neither infinity nor negative infinity).
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
This rule appears in the C++ Secure Coding Standard as FLP03-CPP. Detect and handle floating point errors.
References
Wiki Markup |
---|
\[[IEEE 754|AA. C References#IEEE 754 2006]\] \[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] |