CWE
Home > CWE List > CWE- Individual Dictionary Definition (1.1)  
Search by ID:

CWE-596: Incorrect Semantic Object Comparison

Individual Definition in a New Window
Incorrect Semantic Object Comparison
Status: Incomplete
Weakness ID: 596 (Weakness Base)
Description
Summary

The software does not correctly compare two objects based on their conceptual content.

Detection Factors

Requires domain-specific knowledge to determine if the comparison is incorrect.

Demonstrative Examples

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.

Java Example:
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()));
}
}
Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory569Expression Issues
Development Concepts (primary)699
ChildOfWeakness ClassWeakness ClassWeakness Class697Insufficient Comparison
Research Concepts (primary)1000
ChildOfCategoryCategory171Cleansing, Canonicalization, and Comparison Errors
Development Concepts699
Time of Introduction
* Implementation
Content History
Modifications
Sean Eidemiller. Cigital. 2008-07-01. (External)
added/updated demonstrative examples
Eric Dalci. Cigital. 2008-07-01. (External)
updated Time_of_Introduction
CWE Content Team. MITRE. 2008-09-08. (Internal)
updated Description, Detection_Factors, Relationships
Previous Entry Names
* Incorrect Object Comparison: Semantic (changed 2008-04-11)
Page Last Updated: November 24, 2008