Pointer from an unsecure source may be NULL or point to unknown memory
This defect occurs when:
Tainted NULL pointer — the pointer obtained from an unsecure source is not validated against NULL.
Tainted size pointer — the size of the memory zone that an unsecure pointer points to is not validated.
Note
On a single pointer, your code can have instances of Use of tainted pointer, Pointer dereference with tainted offset, and Tainted NULL or non-null-terminated string. Bug Finder raises only the first tainted pointer defect that it finds.
To consider all input from outside the current analysis perimeter as unsecure, use
-consider-analysis-perimeter-as-trust-boundary.
An attacker can give your program a pointer that points to unexpected memory locations. If the pointer is dereferenced to write, the attacker can:
Modify the state variables of a critical program.
Cause your program to crash.
Execute unwanted code.
If the pointer is dereferenced to read, the attacker can:
Read sensitive data.
Cause your program to crash.
Modify a program variable to an unexpected value.
Avoid use of pointers from external sources.
Alternatively, if you trust the external source, sanitize the pointer before dereference. In a separate sanitization function:
Check that the pointer is not NULL.
Check the size of the memory location (if possible). This second check validates whether the size of the data the pointer points to matches the size your program expects.
The defect still appears in the body of the sanitization function. However, if you use a sanitization function, instead of several occurrences, the defect appears only once. You can justify the defect and hide it in later reviews by using code annotations. See Address Polyspace Results Through Bug Fixes or Justifications.
| Group: Tainted Data |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax: TAINTED_PTR |
| Impact: Low |
| CWE ID: 690, 822 |
-consider-analysis-perimeter-as-trust-boundary | Find defects
(-checkers) | Pointer dereference with tainted offset