PKUMAR077244 (Community Member) asked a question.

Hi ,
How to fix CWE-190: Integer Overflow or Wraparound.
Flaws statement given below and code (with flaws line in bold).

This arithmetic operation results in an integer overflow error. Because the result of this calculation is larger than the maximum possible value for this data type, the result may wrap to become a very small, or negative number, therefore providing an unintended value. Integer overflows can often trigger buffer overflows, which can be exploited to execute arbitrary code. Verify that the result of the calculation does not wrap around before passing the result into other functions.

 

//code

unsigned k; //SAST general

unsigned char sess_buff[ SPDU_BUFFER_SIZE ]; /* save size */

char *usci_called_addr;

if((k+strlen(usci_calling_addr)+1) < SPDU_BUFFER_SIZE) strcpy( (char *) &sess_buff[k], (char *) usci_calling_addr );

k += strlen( (char *) usci_calling_addr ); //flaw line

 

Thanks,

Pankaj Kumar

 

 


Topics (2)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.