Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This noncompliant code example may result in an unsigned integer wrap during the addition of the unsigned operands ui_a and ui_b. If this behavior is unexpected, the resulting value may be used to allocate insufficient memory for a subsequent operation or in some other manner that can lead to an exploitable vulnerability.

Code Block
bgColor#FFcccc
langc
unsigned int ui_a;
unsigned int ui_b;
unsigned int usum;

void func(void) {
  /* Initialize ui_a and ui_b */
  usum = ui_a + ui_b;

  /* ... */
}

...

  • Operations on two compile-time constants
  • Operations on a variable and 0 (except division by 0, of course)
  • Subtracting any variable from its type's maximum; for instance, any unsigned int may safely be subtracted from UINT_MAX
  • Multiplying any variable by 1
  • Division, as long as the divisor is nonzero
  • Right-shifting any type maximum by any number smaller than the type size; for instance, UINT_MAX >> x is valid as long as 0 <=  x < 32 (assuming that the size of unsigned int is 32 bits)
  • Left-shifting 1 by any number smaller than the type size

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

INT30-C

highHigh

likelyLikely

highHigh

P9

L2

Automated Detection

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect violations of this rule by ensuring that operations are checked for overflow before being performed. Be mindful of exception INT30-EX2 because it excuses many operations from requiring validation, including all the operations that would validate a potentially dangerous operation. For instance, adding two unsigned ints together requires validation involving subtracting one of the numbers from UINT_MAX, which itself requires no validation because it cannot wrap

Coverity6.5INTEGER_OVERFLOWImplemented

Fortify SCA

5.0

 

Can detect violations of this rule with the CERT C Rule Pack

PRQA QA-C
Include Page
PRQA_V
PRQA_V

2910 (C)
2911 (D)
2912 (A)
2913 (S)
3302
3303
3304

Partially implemented

...