Katalog CWE

CWE-193 · Słabość

Off-by-one Error

Abstrakcja
Bazowa
Status
Szkic
Dodano
19 lipca 2006
Ostatnia zmiana
11 grudnia 2025

Podatności CVE z tą słabościąPełny wpis na cwe.mitre.org ↗

Opis

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

Inne nazwy

off-by-five
An "off-by-five" error was reported for sudo in 2002 (CVE-2002-0184), but that is more like a "length calculation" error.

Skutki

  • Availability

    DoS: Crash, Exit, or Restart; DoS: Resource Consumption (CPU); DoS: Resource Consumption (Memory); DoS: Instability

    This weakness will generally lead to undefined behavior and therefore crashes. In the case of overflows involving loop index variables, the likelihood of infinite loops is also high.

  • Integrity

    Modify Memory

    If the value in question is important to data (as opposed to flow), simple data corruption has occurred. Also, if the wrap around results in other conditions such as buffer overflows, further memory corruption may occur.

  • Confidentiality, Availability, Access Control

    Execute Unauthorized Code or Commands; Bypass Protection Mechanism

    This weakness can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a program's implicit security policy.

Zapobieganie

  • Implementation

    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().

Przykłady podatności

Słabość nadrzędna

Może prowadzić do

Kiedy powstaje

Dotyczy

C, Not Language-Specific

Uwagi

This is not always a buffer overflow. For example, an off-by-one error could be a factor in a partial comparison, a read from the wrong memory location, an incorrect conditional, etc.

Źródła

  1. Third Generation Exploits — Halvar Flake, presentation at Black Hat Europe 2001
  2. Off-by-one errors: a brief explanation — Steve Christey, Secprog and SC-L mailing list posts, 2004
  3. The Frame Pointer Overwrite — klog, Phrack Issue 55, Chapter 8, 1999
  4. Exploiting Software: How to Break Code — Greg Hoglund, Gary McGraw, Chapter 7, "Buffer Overflow", Addison-Wesley, 2004
  5. 24 Deadly Sins of Software Security — Michael Howard, David LeBlanc, John Viega, "Sin 5: Buffer Overruns." Page 89, McGraw-Hill, 2010
  6. The Art of Software Security Assessment — Mark Dowd, John McDonald, Justin Schuh, Chapter 5, "Off-by-One Errors", Page 180, Addison Wesley, 2006

Wpis z katalogu CWE 4.20.