Checkers:ABV.MEMBER
From current
Buffer overflow—array index out of bounds in a structure
ABV.MEMBER checks for array bounds violations in a class or structure. The checker flags any code in which a buffer overflow will occur as a result of this situation. This checker has been extracted from checker ABV.GENERAL to find these specific buffer overflow situations separately, in case you habitually overflow the structure in your code, in which case you would want to turn this checker off.
Vulnerability and risk
For information on vulnerability and risk in buffer overflows, see Understanding buffer overflows.
Code examples
Vulnerable code example
1 typedef struct Data { 2 int kind; 3 char name[8]; 4 char ext[3]; 5 } Data; 6 7 void resetDefaults(Data *d) 8 { 9 d->kind = 0; 10 memset(d->name, 0, 11); 11 }
Klocwork produces an ABV.MEMBER report at line 10, indicating that array 'd->name' will overflow. If the design intention is to zero the name and extension, then this code isn't a problem. Otherwise, it's best to make the change shown in the following example.
Fixed code example
1 typedef struct Data { 2 int kind; 3 char name[8]; 4 char ext[3]; 5 } Data; 6 7 void resetDefaults(Data *d) 8 { 9 d->kind = 0; 10 memset(d->name, 0, 8); 11 memset(d->ext, 0, 3); 12 }
In the fixed code example, the size of the array has been changed so that array 'd->name' isn't used as an alias for both 'name' and 'ext'.
Related checkers
- ABV.ANY_SIZE_ARRAY
- ABV.GENERAL
- ABV.ITERATOR
- ABV.MEMBER
- ABV.TAINTED
- NNTS.MIGHT
- NNTS.TAINTED
- SV.STRBO.BOUND_SPRINTF
- SV.STRBO.BOUND_COPY
- SV.STRBO.UNBOUND_COPY
- SV.STRBO.UNBOUND_SPRINTF
External guidance
- CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
- 2010 CWE/SANS Top 25 Most Dangerous Programming Errors
- ARR30-C: Do not form or use out of bounds pointers or array subscripts
- STIG-ID:APP3590.1 Application is vulnerable to buffer overflows
Extension
This checker can be extended through the Klocwork knowledge base. See Tuning C/C++ analysis for more information.


