Skip to content

Off-by-one error

Description

The software calculates or uses an incorrect maximum or minimum value that is 1 more, or 1 less, than the correct value, which can lead to buffer overflows, out-of-bounds access, or other security vulnerabilities.

Examples

Insecure Code

c
char buf[10]; buf[10] = 'a';

Secure Code

c
char buf[10]; buf[9] = 'a';

Remediation

Review the code to ensure that buffer sizes and indices are correctly calculated, and consider using size-aware functions to prevent off-by-one errors.

Rule Details

FieldValue
IDCODE-0738
CategoryInjection
SeverityHIGH
CWECWE-193
ConfidenceMEDIUM
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsbuffer overflow, off-by-one
OWASPN/A

References