PVS-StudioWarnings

PVS-Studio warning V547 for UltimateTCPIP

Nov 26th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. void CUT_StrMethods::RemoveCRLF(LPSTR buf)
  2. {
  3.   // v4.2 changed to size_t
  4.   size_t  len, indx = 1;
  5.   if(buf != NULL){
  6.     len = strlen(buf);
  7.     while((len - indx) >= 0 && indx <= 2) {
  8.       if(buf[len - indx] == '\r' ||
  9.          buf[len - indx] == '\n')
  10.          buf[len - indx] = 0;
  11.       ++indx;
  12.     }
  13.   }
  14. }
  15.  
  16. This is an example of vulnerability. When processing an empty string, the (len - indx) expression will equal 0xFFFFFFFFu. The value 0xFFFFFFFFu is above 0. An array overrun will occur.
  17.  
  18.  
  19. This suspicious code was found in UltimateTCPIP project by PVS-Studio static code analyzer.
  20. Warning message is:
  21. V547 Expression '( len - indx ) >= 0' is always true. Unsigned type value is always >= 0. UTDns utstrlst.cpp 58
  22.  
  23. PVS-Studio is a static analyzer for detecting bugs in the source code of applications written in C, C++, C++11, C++/CX. Site: http://www.viva64.com/en/pvs-studio/
Advertisement
Add Comment
Please, Sign In to add comment