VNX-788: Access of Memory Location After End of Buffer
C/C++ off-by-one accesses: X[sizeof(X)], X[N] on an array declared X[N], loops bounded by i <= N, and a full-size read() followed by X[n] = 0.
| Field | Value |
|---|---|
| Rule ID | VNX-788 |
| Severity | High |
| SARIF level | error |
| Kind | sast |
| Languages | C, C++ |
| CWE | CWE-788 |
| CAPEC | CAPEC-66 |
| ATT&CK | T1190 |
| CWSS vector | CWSS:1.0/TI:H/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:H/DI:H/EX:H/EC:N/P:H |
| Tags | oob-access-after-end cwe-788 |
| Source | internal/sast/rules/vnx-788.rego |
Overview
VNX-788 maps to CWE-788: Access of Memory Location After End of Buffer. It reports C and C++ accesses one element past the end of an array declared in the same file:
X[sizeof(X)]orX[sizeof X]X[N]where the nearest declaration ofXisT X[N](N a number or a constant)- a
forloop bounded byi <= Nori <= sizeof(X)that indexesX[i]in its body n = read(fd, X, sizeof X)(alsorecv,pread,fread(X, 1, ...)) followed byX[n] = ..., where a full read leaves no room for the terminator
Arrays declared elsewhere, struct members, pointer buffers, &X[N] (a valid one-past-the-end pointer) and bounds computed at run time are not reported.
Why This Matters
Valid indexes run from 0 to size - 1. Writing at index size corrupts whatever follows the array (another variable, a saved frame pointer, heap metadata), and reading it leaks adjacent memory.
What Gets Flagged
char name[32];
name[sizeof(name)] = '\0'; // FLAGGED
int vals[N];
for (i = 0; i <= N; i++) // FLAGGED: runs to vals[N]
total += vals[i];
ssize_t got = read(fd, req, sizeof(req));
req[got] = '\0'; // FLAGGED: got can equal sizeof(req)
Remediation
- Terminate at
sizeof(buf) - 1and read at mostsizeof(buf) - 1bytes. - Bound loops with
i < N.
References
Suppressing this rule
Put a nosec comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file’s language (#, //, -- or ;):
# nosec vnx-788
// nosec vnx-788
Or record an ignore rule: vulnetix ignore add --rule vnx-788 --reason "...". See Suppressing findings.