Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: xref STR31-C in buffer overflow NCCE

...

This example is still problematic because a buffer overflow will occur if the null-terminated byte string referenced by msg is greater than 17 characters, including the null terminator. For more information, see STR31-C. Guarantee that storage for strings has sufficient space for character data and the null terminator.

Compliant Solution

In this compliant solution, the buffer overflow is eliminated by using the snprintf() function:

...