Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Alternative functions that limit the number of bytes copied are often recommended to mitigate buffer overflow vulnerabilities. For example:

  • strncpy() instead of strcpy()
  • strncat() instead of strcat()
  • fgets() instead of gets()
  • snprintf() instead of sprintf()

Wiki Markup
These functions truncate strings that exceed the specified limits. Additionally, some functions such as {{strncpy()}} do not guarantee that the resulting string is null-terminated \[[STR33-C|STR33-C. Guarantee that all strings are null-terminated]\].

Truncation results in a loss of data and, in some cases, leads to software vulnerabilities.

Include Page
c:STR34 NCCE
c:STR34 NCCE
Include Page
c:STR34 CS 1
c:STR34 CS 1
Include Page
c:STR34 CS 2
c:STR34 CS 2

Exception

An exception to this rule applies if the intent of the programmer was to intentionally truncate the null-terminated byte string. To be compliant with this standard, this intent must be clearly stated in comments.

Priority: P2 Level: L3

Truncating strings can lead to a loss of data and, in some cases, exploitable vulnerabilities.

Component

Value

Severity

1 (low)

Likelihood

1 (unlikely)

Remediation cost

2 (medium)

References