CWE-839: Numeric Range Comparison Without Minimum Check

What is CWE-839?

CWE-839 is Numeric Range Comparison Without Minimum Check. The flaw arises when 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. The database currently holds 4 vulnerabilities mapped to CWE-839 and none of them are in the CISA Known Exploited Vulnerabilities catalog.

OWASP Top 10 Rank-
Related CVES (365 days)4
AbstractionBase
Likelihood of exploit-

Vulnerabilities mapped to CWE-839

4 vulnerabilities

No data

No vulnerability data in CISA KEV for CWE-839

Official definition

ByMitre CWE

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.

Characteristics

Alternate terms

  • 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.

Modes of introduction

  • Implementation: 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.

Common consequences

ImpactScopeExplanation
Modify Memory, Read MemoryConfidentiality, IntegrityIf a negative value is used to access memory, buffers, or other indexable structures, it could access memory outside the bounds of the buffer.
DoS: Resource Consumption (Memory), DoS: Resource Consumption (Other)AvailabilityIn some contexts, a negative value could lead to resource consumption, e.g., if the negative value is used for memory allocation.
Modify Application Data, Execute Unauthorized Code or CommandsIntegrity, Confidentiality, AvailabilityAn attacker could modify the structure of the message or data being sent to the downstream component, possibly injecting commands.
Varies by Context, Unexpected StateIntegrityThe 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.

Risk mitigations

  1. Enforcement by Conversion · ImplementationIf the number to be used is always expected to be positive, change the variable type from signed to unsigned or size_t.
  2. Input Validation · ImplementationIf 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

MethodApproachEffectiveness
Automated Static AnalysisAutomated 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.)-

Representative vulnerabilities

Sources (2)

CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.

Learn more

Run an in-depth assessment with complete web risk management

CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.