1868
Description
The product performs a comparison between two entities, but the entities are of different,
incompatible types that cannot be guaranteed to provide correct results when they are directly
compared.
Extended Description
In languages that are strictly typed but support casting/conversion, such as C or C++, the
programmer might assume that casting one entity to the same type as another entity will ensure
that the comparison will be performed correctly, but this cannot be guaranteed. In languages that
are not strictly typed, such as PHP or JavaScript, there may be implicit casting/conversion to a type
that the programmer is unaware of, causing unexpected results; for example, the string "123" might
be converted to a number type. See examples.
Relationships
The table(s) below shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOr and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition, relationships such
as PeerOf and CanAlsoBe are defined to show similar weaknesses that may want to be explored.
Relevant to the view "Research Concepts" (CWE-1000)
Nature Type ID Name Page
ChildOf 697 Incorrect Comparison 1530
Relevant to the view "Software Development" (CWE-699)
Nature Type ID Name Page
MemberOf 19 Data Processing Errors 2309
Weakness Ordinalities
Primary :
Applicable Platforms
Language : JavaScript (Prevalence = Undetermined)
Language : PHP (Prevalence = Undetermined)
Language : Not Language-Specific (Prevalence = Undetermined)
Common Consequences
Scope Impact Likelihood
Other Varies by Context
Potential Mitigations
Phase: Testing
Thoroughly test the comparison scheme before deploying code into production. Perform positive
testing as well as negative testing.
MemberOf Relationships
This MemberOf relationships table shows additional CWE Catgeories and Views that reference this
weakness as a member. This information is often useful in understanding where a weakness fits
within the context of external information sources.
Nature Type ID Name Page
MemberOf 1397 Comprehensive Categorization: Comparison 1400 2523
CWE-1025: Comparison Using Wrong Factors
CWE Version 4.14
CWE-1025: Comparison Using Wrong Factors
CWE-1025: Comparison Using Wrong Factors