CWE-193

Off-by-one Error
AI Translation Available

A product calculates or uses an incorrect maximum or minimum value that is 1 more, or 1 less, than the correct value.

Status
draft
Abstraction
base
C Not Language-Specific

Common Consequences

availability integrity confidentiality access control
Impacts
dos: crash, exit, or restart dos: resource consumption (cpu) dos: resource consumption (memory) dos: instability modify memory execute unauthorized code or commands bypass protection mechanism

Detection Methods

automated static analysis

Potential Mitigations

Phases:
implementation
Descriptions:
• When copying character arrays or using character manipulation methods, the correct size parameter must be used to account for the null terminator that needs to be added at the end of the array. Some examples of functions susceptible to this weakness in C include strcpy(), strncpy(), strcat(), strncat(), printf(), sprintf(), scanf() and sscanf().