Destination buffer underflow in string manipulation
Function writes to buffer at a negative offset from beginning of buffer
Description
This defect occurs when certain string manipulation functions write to their destination buffer argument at a negative offset from the beginning of the buffer.
For instance, for the function sprintf(char* buffer,
const char* format)
, you obtain the buffer
from
an operation buffer = (char*)arr; ... buffer += offset;
. arr
is
an array and offset
is a negative value.
Risk
Buffer underflow can cause unexpected behavior such as memory corruption or stopping your system. Buffer underflow also introduces the risk of code injection.
Fix
If the destination buffer argument results from pointer arithmetic, see if you are decrementing a pointer. Fix the pointer decrement by modifying either the original value before decrement or the decrement value.
Examples
Result Information
Group: Static memory |
Language: C | C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax: STRLIB_BUFFER_UNDERFLOW |
Impact: High |
Version History
Introduced in R2015b
See Also
Find defects (-checkers)
| Destination buffer overflow in string manipulation
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)