CWE-839 詳細資料

CWE-839

Numeric Range Comparison Without Minimum Check
2011-03-30
00h00 +00:00
Incomplete
2026-10-28
00h00 +00:00
指定 CWE 通知
掌握特定 CWE 的任何變更。
管理通知

名稱: Numeric Range Comparison Without Minimum Check

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.

一般資訊

引入方式

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.

適用平台

程式語言

名稱: C (Often)
名稱: C++ (Often)

常見後果

範圍 影響 可能性
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.
AvailabilityDoS: 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.
IntegrityVaries 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.

觀察到的案例

參考資料 描述

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.

潛在緩解措施

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

偵測方法

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

漏洞對應備注

理由說明 : This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
備註 : Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.

參考資料

REF-62

The Art of Software Security Assessment
Mark Dowd, John McDonald, Justin Schuh.

REF-62

The Art of Software Security Assessment
Mark Dowd, John McDonald, Justin Schuh.

提交

名稱 機構 日期 發布日期 Version
CWE Content Team MITRE 2011-03-24 +00:00 2011-03-30 +00:00 1.12

修改記錄

名稱 機構 日期 備註
CWE Content Team MITRE 2011-06-01 +00:00 updated Common_Consequences
CWE Content Team MITRE 2012-05-11 +00:00 updated Demonstrative_Examples, References, Relationships
CWE Content Team MITRE 2014-02-18 +00:00 updated Relationships
CWE Content Team MITRE 2018-03-27 +00:00 updated Description
CWE Content Team MITRE 2019-01-03 +00:00 updated Relationships
CWE Content Team MITRE 2023-01-31 +00:00 updated Alternate_Terms, Description
CWE Content Team MITRE 2023-04-27 +00:00 updated Relationships
CWE Content Team MITRE 2023-06-29 +00:00 updated Mapping_Notes
CWE Content Team MITRE 2023-10-26 +00:00 updated Observed_Examples
CWE Content Team MITRE 2025-09-09 +00:00 updated Demonstrative_Examples
CWE Content Team MITRE 2025-12-11 +00:00 updated Detection_Factors, Time_of_Introduction, Weakness_Ordinalities
CWE Content Team MITRE 2026-10-28 +00:00 updated Common_Consequences, Description, Modes_of_Introduction, Relationships