Katalog CWE

CWE-839 · Słabość

Numeric Range Comparison Without Minimum Check

Abstrakcja
Bazowa
Status
Niekompletny
Dodano
24 marca 2011
Ostatnia zmiana
11 grudnia 2025

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

Opis

The product checks a value to ensure that it is less than or equal to a maximum, but it does not also verify that the value is greater than or equal to the minimum.

Some products use signed integers or floats even when their values are only expected to be positive or 0. An input validation check might assume that the value is positive, and only check for the maximum value. If the value is negative, but the code assumes that the value is positive, this can produce an error. The error may have security consequences if the negative value is used for memory allocation, array access, buffer access, etc. Ultimately, the error could lead to a buffer overflow or other type of memory corruption.

The use of a negative number in a positive-only context could have security implications for other types of resources. For example, a shopping cart might check that the user is not requesting more than 10 items, but a request for -3 items could cause the application to calculate a negative price and credit the attacker's account.

Inne nazwy

Signed comparison
The "signed comparison" term is often used to describe when the product uses a signed variable and checks it to ensure that it is less than a maximum value (typically a maximum buffer size), but does not verify that it is greater than 0.

Skutki

  • Integrity, Confidentiality, Availability

    Modify Application Data; Execute Unauthorized Code or Commands

    An attacker could modify the structure of the message or data being sent to the downstream component, possibly injecting commands.

  • Availability

    DoS: Resource Consumption (Other)

    in some contexts, a negative value could lead to resource consumption.

  • Confidentiality, Integrity

    Modify Memory; Read Memory

    If a negative value is used to access memory, buffers, or other indexable structures, it could access memory outside the bounds of the buffer.

Zapobieganie

  • Implementation · Enforcement by Conversion

    If the number to be used is always expected to be positive, change the variable type from signed to unsigned or size_t.

  • Implementation · Input Validation

    If the number to be used could have a negative value based on the specification (thus requiring a signed value), but the number should only be positive to preserve code correctness, then include a check to ensure that the value is positive.

Przykłady podatności

Słabość nadrzędna

Może prowadzić do

Kiedy powstaje

Dotyczy

C, C++

Źródła

  1. The Art of Software Security Assessment — Mark Dowd, John McDonald, Justin Schuh, Chapter 6, "Type Conversion Vulnerabilities" Page 246, Addison Wesley, 2006
  2. The Art of Software Security Assessment — Mark Dowd, John McDonald, Justin Schuh, Chapter 6, "Comparisons", Page 265, Addison Wesley, 2006

Wpis z katalogu CWE 4.20.