Incorrect Semantic Object Comparison |
Weakness ID: 596 (Weakness Base) | Status: Incomplete |
Description Summary
The software does not correctly compare two objects based on their conceptual content.
Manual Static Analysis Requires domain-specific knowledge to determine if the comparison is incorrect. |
Example 1
For example, let's say you have two truck objects that you want to compare for equality. Truck objects are defined to be the same if they have the same make, the same model, and were manufactured in the same year. A Semantic Incorrect Object Comparison would occur if only two of the three factors were checked for equality. So if only make and model are compared and the year is ignored, then you have an incorrect object comparison.
(Bad Code)
Example Language: Java
public class Truck {
private String make;
private String model;
private int year;
public boolean equals(Object o) {
if (o == null) return false;
if (o == this) return true;
if (!(o instanceof Truck)) return false;
Truck t = (Truck) o;
return (this.make.equals(t.getMake()) && this.model.equals(t.getModel()));
}
}
Nature | Type | ID | Name | View(s) this relationship pertains to![]() |
---|---|---|---|---|
ChildOf | ![]() | 171 | Cleansing, Canonicalization, and Comparison Errors | Development Concepts699 |
ChildOf | ![]() | 569 | Expression Issues | Development Concepts (primary)699 |
ChildOf | ![]() | 697 | Insufficient Comparison | Research Concepts (primary)1000 |
Modifications | ||||
---|---|---|---|---|
Modification Date | Modifier | Organization | Source | |
2008-07-01 | Sean Eidemiller | Cigital | External | |
added/updated demonstrative examples | ||||
2008-07-01 | Eric Dalci | Cigital | External | |
updated Time of Introduction | ||||
2008-09-08 | CWE Content Team | MITRE | Internal | |
updated Description, Detection Factors, Relationships | ||||
Previous Entry Names | ||||
Change Date | Previous Entry Name | |||
2008-04-11 | Incorrect Object Comparison: Semantic | |||