Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

ABV.MEMBER

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

Consequences of buffer overflow include valid data being overwritten and execution of arbitrary and potentially malicious code.

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'.

Extension

This checker can be extended through the Klocwork knowledge base. See Tuning C/C++ analysis for more information.