CWEweakness

CWE-839 Numeric Range Comparison Without Minimum Check

Official page ↗
Alternate terms
Signed comparison
Abstraction
Base
Structure
Simple
Status
Incomplete
Languages
C, C++
CWE version
5.0

Description

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.

Common consequences

• 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. • Availability: DoS: Resource Consumption (Memory), DoS: Resource Consumption (Other) — In some contexts, a negative value could lead to resource consumption, e.g., if the negative value is used for memory allocation. • 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. • Integrity: Varies by Context, Unexpected State — 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.

Potential mitigations

• [Implementation] If the number to be used is always expected to be positive, change the variable type from signed to unsigned or size_t. • [Implementation] 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.

Detection methods

• Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Observed examples

• CVE-2010-1866: Chain: integer overflow (CWE-190) causes a negative signed value, which later bypasses a maximum-only check (CWE-839), leading to heap-based buffer overflow (CWE-122). • CVE-2009-1099: Chain: 16-bit counter can be interpreted as a negative value, compared to a 32-bit maximum value, leading to buffer under-write. • CVE-2011-0521: Chain: kernel's lack of a check for a negative value leads to memory corruption. • CVE-2010-3704: Chain: parser uses atoi() but does not check for a negative value, which can happen on some platforms, leading to buffer under-write. • CVE-2010-2530: Chain: Negative value stored in an int bypasses a size check and causes allocation of large amounts of memory. • CVE-2009-3080: Chain: negative offset value to IOCTL bypasses check for maximum index, then used as an array index for buffer under-read. • CVE-2008-6393: Chain: file transfer client performs signed comparison, leading to integer overflow and heap-based buffer overflow. • CVE-2008-4558: Chain: negative ID in media player bypasses check for maximum index, then used as an array index for buffer under-read.

Related

Observed example · CVE (8)

  • CVE-2011-0521 The dvb_ca_ioctl function in drivers/media/dvb/ttpci/av7110_ca.c in the Linux kernel before 2.6.38-rc2 does not check the sign of a certain… vulnerability
  • CVE-2010-3704 The FoFiType1::parse function in fofi/FoFiType1.cc in the PDF parser in xpdf before 3.02pl5, poppler 0.8.7 and possibly other versions up… vulnerability
  • CVE-2010-2530 Multiple integer signedness errors in smb_subr.c in the netsmb module in the kernel in NetBSD 5.0.2 and earlier, FreeBSD, and Apple Mac OS… vulnerability
  • CVE-2010-1866 The dechunk filter in PHP 5.3 through 5.3.2, when decoding an HTTP chunked encoding stream, allows context-dependent attackers to cause a… vulnerability
  • CVE-2009-3080 Array index error in the gdth_read_event function in drivers/scsi/gdth.c in the Linux kernel before 2.6.32-rc8 allows local users to cause… vulnerability
  • CVE-2009-1099 Integer signedness error in Java SE Development Kit (JDK) and Java Runtime Environment (JRE) 5.0 Update 17 and earlier, and 6 Update 12 and… vulnerability
  • CVE-2008-6393 PSI Jabber client before 0.12.1 allows remote attackers to cause a denial of service (crash) and possibly execute arbitrary code via a file… vulnerability
  • CVE-2008-4558 Array index error in VLC media player 0.9.2 allows remote attackers to overwrite arbitrary memory and execute arbitrary code via an XSPF… vulnerability

Can precede · CWE (4)

  • CWE-119 Improper Restriction of Operations within the Bounds of a Memory Buffer weakness
  • CWE-124 Buffer Underwrite weakness
  • CWE-195 Signed to Unsigned Conversion Error weakness
  • CWE-682 Incorrect Calculation weakness

Child of · CWE (2)

  • CWE-1023 Incomplete Comparison with Missing Factors weakness
  • CWE-1284 Improper Validation of Specified Quantity in Input weakness

Referenced by CVE · weakness (8)

  • CVE-2026-118384 GNU mtools through 4.0.49 has an out-of-bounds write in parse_vses in vfat.c. vulnerability
  • CVE-2026-57186 Asterisk is an open source private branch exchange and telephony toolkit. vulnerability
  • CVE-2026-53176 In the Linux kernel, the following vulnerability has been resolved: IB/isert: Reject login PDUs shorter than ISER_HEADERS_LEN In… vulnerability
  • CVE-2026-56968 GNU SASL before 2.2.4 lacks sanitization of a short challenge in _gsasl_ntlm_client_step in the NTLM client, which could result in memory… vulnerability
  • CVE-2026-48840 Exim 4.88 before 4.99.4, in some proxy configurations, mishandles certain short payloads, leading to disclosure of uninitialized stack… vulnerability
  • CVE-2023-0425 ABB is aware of vulnerabilities in the product versions listed below. vulnerability
  • CVE-2023-22854 The ccmweb component of Mitel MiContact Center Business server 9.2.2.0 through 9.4.1.0 could allow an unauthenticated attacker to download… vulnerability
  • CVE-2019-20925 An unauthenticated client can trigger denial of service by issuing specially crafted wire protocol messages, which cause the message… vulnerability

Referenced by CWE · has member (1)