Tainted NULL or non-null-terminated string
Argument is from an unsecure source and might be NULL or not NULL-terminated
Description
This defect occurs when strings from unsecure sources are used in string manipulation routines
that implicitly dereference the string buffer, for instance, strcpy or
sprintf.
Tainted NULL or non-null-terminated string raises no
defect for a string returned from a call to scanf-family variadic
functions. Similarly, no defect is raised when you pass the string with a
%s specifier to printf-family variadic
functions.
Risk
If a string is from an unsecure source, it is possible that an attacker manipulated the string or pointed the string pointer to a different memory location.
If the string is NULL, the string routine cannot dereference the string, causing the program to crash. If the string is not null-terminated, the string routine might not know when the string ends. This error can cause you to write out of bounds, causing a buffer overflow.
Fix
Validate the string before you use it. Check that:
The string is not NULL.
The string is null-terminated
The size of the string matches the expected size.
Extend Checker
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.
Examples
Result Information
| Group: Tainted Data |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax: TAINTED_STRING |
| Impact: Low |
Version History
Introduced in R2015b
See Also
Tainted string format | Find defects
(-checkers) | -consider-analysis-perimeter-as-trust-boundary
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)
- Sources of Tainting in a Polyspace Analysis
- Modify Default Behavior of Bug Finder Checkers