...
Code Block |
---|
char src1[100] = "hello"; char src2[8] = {'g','o','o','d','b','y','e','\0'}; char dst1[6],; char dst2[5]; int r1,; int r2; r1 = strcpy_s(dst1, sizeof(dst1), src1); r2 = strcpy_s(dst2, sizeof(dst2), src2); |
...
Users of the C11 Annex K functions are less likely to introduce a security flaw because the size of the destination buffer and the maximum number of characters to append must be specified. ISO/IEC TR 24731 Part II [ISO/IEC TR 24731-2:2010] offers another approach, supplying functions that allocate enough memory for their results. ISO/IEC TR 24731 Part II functions also ensure null termination of the destination string.
ISO/IEC TR 24731-1 [ISO/IEC TR 24731-1:2007] C11 Annex K functions are still capable of overflowing a buffer if the maximum length of the destination buffer and number of characters to copy are incorrectly specified. ISO/IEC TR 24731 -2 Part II functions can make it more difficult to keep track of memory that must be freed, leading to memory leaks. As a result, the C11 Annex K and the ISO/IEC TR 24731 Part II functions are not particularly secure but may be useful in preventive maintenance to reduce the likelihood of vulnerabilities in an existing legacy code base.
...
String-handling functions defined in the C Standard, Section 7.24 [ISO/IEC 9899:2011], and elsewhere are susceptible to common programming errors that can lead to serious, exploitable vulnerabilities. Proper use of TR 24731 the C11 Annex K functions can eliminate most of these issues.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
ISO/IEC TR 24731-1:20079899:2011 | Annex K |
ISO/IEC TR 24731-2:2010 | |
ISO/IEC TR 24772:2013 | Use of Libraries [TRJ] |
...