Constant array index outside the declared bounds

Constant array index outside the declared bounds

Description

Accessing a fixed-size array with a constant index outside its bounds can read or write adjacent memory.

Potential impact

  • Memory corruption, information disclosure or crashes.

Remediation

Use only indices within the array's bounds. Review loop conditions and constant indices alongside the array declaration.

Examples

Before

c
int values[4];
values[4] = 1;

After

c
int values[4];
values[3] = 1;

An array of four elements has valid indices from 0 through 3. The second excerpt accesses its last valid element.

References