Skip to content

Integer Overflow or Wraparound

Description

The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.

Examples

Insecure Code

c
size_t len = strlen(user_input); char* buf = malloc(len * sizeof(char));

Secure Code

c
size_t len = strlen(user_input); if (len > SIZE_MAX / sizeof(char)) { /* handle error */ } char* buf = malloc(len * sizeof(char));

Remediation

Check for potential overflows before performing calculations and allocate sufficient memory to prevent integer overflows.

Rule Details

FieldValue
IDCODE-0188
CategoryInjection
SeverityHIGH
CWECWE-190
ConfidenceMEDIUM
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsinteger overflow, wraparound
OWASPN/A

References