Function writes to buffer at a negative offset from beginning of buffer
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.
Buffer underflow can cause unexpected behavior such as memory corruption or stopping your system. Buffer underflow also introduces the risk of code injection.
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.
| Group: Static memory |
| Language: C | C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax: STRLIB_BUFFER_UNDERFLOW |
| Impact: High |
| CWE ID: 124, 786, 787 |