@@ -44,10 +44,13 @@ namespace {
4444// ---------------------------------------------------------------------------
4545
4646// CWE ids used:
47- static const CWE CWE131 (131U );
48- static const CWE CWE398 (398U );
49- static const CWE CWE786 (786U );
50- static const CWE CWE788 (788U );
47+ static const CWE CWE131 (131U ); // Incorrect Calculation of Buffer Size
48+ static const CWE CWE170 (170U ); // Improper Null Termination
49+ static const CWE CWE398 (398U ); // Indicator of Poor Code Quality
50+ static const CWE CWE682 (682U ); // Incorrect Calculation
51+ static const CWE CWE758 (758U ); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
52+ static const CWE CWE786 (786U ); // Access of Memory Location Before Start of Buffer
53+ static const CWE CWE788 (788U ); // Access of Memory Location After End of Buffer
5154
5255// ---------------------------------------------------------------------------
5356
@@ -174,7 +177,7 @@ void CheckBufferOverrun::strncatUsageError(const Token *tok)
174177 " At most, strncat appends the 3rd parameter's amount of characters and adds a terminating null byte.\n "
175178 " The safe way to use strncat is to subtract one from the remaining space in the buffer and use it as 3rd parameter."
176179 " Source: http://www.cplusplus.com/reference/cstring/strncat/\n "
177- " Source: http://www.opensource.apple.com/source/Libc/Libc-167/gen.subproj/i386.subproj/strncat.c" );
180+ " Source: http://www.opensource.apple.com/source/Libc/Libc-167/gen.subproj/i386.subproj/strncat.c" , CWE119, false );
178181}
179182
180183void CheckBufferOverrun::outOfBoundsError (const Token *tok, const std::string &what, const bool show_size_info, const MathLib::bigint &supplied_size, const MathLib::bigint &actual_size)
@@ -219,7 +222,7 @@ void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok)
219222{
220223 if (_settings && !_settings->isEnabled (" warning" ))
221224 return ;
222- reportError (tok, Severity::warning, " sizeArgumentAsChar" , " The size argument is given as a char constant." );
225+ reportError (tok, Severity::warning, " sizeArgumentAsChar" , " The size argument is given as a char constant." , CWE682, false );
223226}
224227
225228
@@ -229,7 +232,7 @@ void CheckBufferOverrun::terminateStrncpyError(const Token *tok, const std::stri
229232 " The buffer '" + varname + " ' may not be null-terminated after the call to strncpy().\n "
230233 " If the source string's size fits or exceeds the given size, strncpy() does not add a "
231234 " zero at the end of the buffer. This causes bugs later in the code if the code "
232- " assumes buffer is null-terminated." , CWE ( 0U ) , true );
235+ " assumes buffer is null-terminated." , CWE170 , true );
233236}
234237
235238void CheckBufferOverrun::cmdLineArgsError (const Token *tok)
@@ -243,7 +246,7 @@ void CheckBufferOverrun::bufferNotZeroTerminatedError(const Token *tok, const st
243246 " The buffer '" + varname + " ' is not null-terminated after the call to " + function + " (). "
244247 " This will cause bugs later in the code if the code assumes the buffer is null-terminated." ;
245248
246- reportError (tok, Severity::warning, " bufferNotZeroTerminated" , errmsg, CWE ( 0U ) , true );
249+ reportError (tok, Severity::warning, " bufferNotZeroTerminated" , errmsg, CWE170 , true );
247250}
248251
249252void CheckBufferOverrun::argumentSizeError (const Token *tok, const std::string &functionName, const std::string &varname)
@@ -1084,7 +1087,7 @@ void CheckBufferOverrun::negativeArraySize()
10841087void CheckBufferOverrun::negativeArraySizeError (const Token *tok)
10851088{
10861089 reportError (tok, Severity::error, " negativeArraySize" ,
1087- " Declaration of array '" + (tok ? tok->str () : std::string ()) + " ' with negative size is undefined behaviour" );
1090+ " Declaration of array '" + (tok ? tok->str () : std::string ()) + " ' with negative size is undefined behaviour" , CWE758, false );
10881091}
10891092
10901093// ---------------------------------------------------------------------------
0 commit comments