293
CanPrecede 124 Buffer Underwrite ('Buffer Underflow') 326
CanPrecede 195 Signed to Unsigned Conversion Error 494
CanPrecede 682 Incorrect Calculation 1499
Relevant to the view "Software Development" (CWE-699)
Nature Type ID Name Page
MemberOf 189 Numeric Errors 2312
Applicable Platforms
Language : C (Prevalence = Often)
Language : C++ (Prevalence = Often)
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.
Common Consequences
Scope Impact Likelihood
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.
Potential Mitigations
Phase: Implementation
Strategy = 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.
Phase: Implementation
Strategy = 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.
Demonstrative Examples
Example 1:
The following code is intended to read an incoming packet from a socket and extract one or more
headers.
CWE Version 4.14
CWE-839: Numeric Range Comparison Without Minimum Check
CWE-839: Numeric Range Comparison Without Minimum Check