CWE
CWE/SANS Top 25 Most Dangerous Software Errors Common Weakness Scoring System
Common Weakness Risk Analysis Framework
Home > CWE List > CWE- Individual Dictionary Definition (2.1)  

CWE-596: Incorrect Semantic Object Comparison

 
Incorrect Semantic Object Comparison
Weakness ID: 596 (Weakness Base)Status: Incomplete
+ Description

Description Summary

The software does not correctly compare two objects based on their conceptual content.
+ Time of Introduction
  • Implementation
+ Common Consequences
ScopeEffect
Other

Technical Impact: Other

+ Detection Methods

Manual Static Analysis

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

+ Demonstrative Examples

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()));
}
}
+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory171Cleansing, Canonicalization, and Comparison Errors
Development Concepts699
ChildOfCategoryCategory569Expression Issues
Development Concepts (primary)699
ChildOfWeakness ClassWeakness Class697Insufficient Comparison
Research Concepts (primary)1000
ChildOfCategoryCategory840Business Logic Errors
Development Concepts699
+ Content History
Modifications
Modification DateModifierOrganizationSource
2008-07-01Sean EidemillerCigitalExternal
added/updated demonstrative examples
2008-07-01Eric DalciCigitalExternal
updated Time_of_Introduction
2008-09-08CWE Content TeamMITREInternal
updated Description, Detection_Factors, Relationships
2010-02-16CWE Content TeamMITREInternal
updated Detection_Factors
2011-03-29CWE Content TeamMITREInternal
updated Relationships
2011-06-01CWE Content TeamMITREInternal
updated Common_Consequences
Previous Entry Names
Change DatePrevious Entry Name
2008-04-11Incorrect Object Comparison: Semantic
Page Last Updated: September 12, 2011