Use of indeterminate string
Use of unvalidated buffer from fgets-family function
Description
This defect occurs when you do not check if a write operation using an
fgets
-family function such
as:
char * fgets(char* buf, int n, FILE *stream)
buf
(as shown above), the checker
raises a defect if:
You pass
buf
as argument to standard functions that print or manipulate strings or wide strings.You return
buf
from a function.You pass
buf
as argument to external functions with parameter typeconst char *
orconst wchar_t *
.You read
buf
asbuf[index]
or*(buf + offset)
, whereindex
oroffset
is a numerical value representing the distance from the beginning of the buffer.
Risk
If an fgets
-family function fails, the content of its output buffer
is indeterminate. Use of such a buffer has undefined behavior and can result in a program
that stops working or other security vulnerabilities.
Fix
Reset the output buffer of an fgets
-family function to a known string
value when the function fails.
Examples
Result Information
Group: Programming |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
INDETERMINATE_STRING
|
Impact: Medium |
Version History
Introduced in R2017b
See Also
Invalid use of standard library string routine
| Returned value of a sensitive function not checked
| Use of
dangerous standard function
| Find defects (-checkers)
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)