Rule Definition
The strcpy, strcmp, strcat, strchr, strspn, strcspn, strpbrk, strrchr, strstr, strtok and strlen functions within the library can read or write beyond the end of a buffer, resulting in undefined behaviour.
Ideally, a safe string handling library should be used.
Remediation
Use functions such as mentioned below to ensure that the copied string is NULL-Terminated:
snprintf
strlcpy
Violation Code Sample
#include <cstring>
void fn ( const char_t * pChar )
{
char_t array [ 10 ];
strcpy ( array, pChar ); // Non-compliant
}
Reference
MISRA C++ 2008, 18-0-5: The unbounded functions of library shall not be used.
Related Technologies
Technical Criterion
CWE-676 - Use of Potentially Dangerous Function
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.