
PKUMAR077244 (Community Member) asked a question.
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
.png)
Hi,
I would recommend you schedule a consultation call to discuss. You can check out this knowledge article (https://community.veracode.com/s/article/How-to-schedule-a-consultation-call) on how to schedule a consultation call with us.
Regards,
Kashif