Skip to content

Commit

Permalink
Merge pull request #180 from Jasper-Ben/fix_false_negative_when_compo…
Browse files Browse the repository at this point in the history
…nent_CPE_part_is_any

CPE: Fix false negative on part comparison
  • Loading branch information
stevespringett committed Sep 4, 2023
2 parents e0db903 + 183ff71 commit 0521b55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/main/java/us/springett/parsers/cpe/Cpe.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,16 @@ public boolean matchedBy(ICpe target) {
* otherwise <code>false</code>
*/
protected static boolean compareAttributes(Part left, Part right) {
//1 6 9 - equals
if (left == right) {
return true;
} else if (left == Part.ANY) {
}
//2 3 - superset (4 does not apply due to enum)
else if (left == Part.ANY) {
return true;
}
//5 13 - subset (15 does not apply due to enum)
else if (right == Part.ANY) {
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/us/springett/parsers/cpe/CpeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public void testCompareAttributes_Part_Part() {
assertFalse(Cpe.compareAttributes(Part.APPLICATION, Part.HARDWARE_DEVICE));
assertFalse(Cpe.compareAttributes(Part.APPLICATION, Part.OPERATING_SYSTEM));
assertFalse(Cpe.compareAttributes(Part.APPLICATION, Part.NA));
assertFalse(Cpe.compareAttributes(Part.APPLICATION, Part.ANY));
assertTrue(Cpe.compareAttributes(Part.APPLICATION, Part.ANY));

assertTrue(Cpe.compareAttributes(Part.ANY, Part.ANY));
assertTrue(Cpe.compareAttributes(Part.ANY, Part.APPLICATION));
Expand All @@ -778,7 +778,7 @@ public void testCompareAttributes_Part_Part() {
assertTrue(Cpe.compareAttributes(Part.ANY, Part.NA));

assertTrue(Cpe.compareAttributes(Part.NA, Part.NA));
assertFalse(Cpe.compareAttributes(Part.NA, Part.ANY));
assertTrue(Cpe.compareAttributes(Part.NA, Part.ANY));
assertFalse(Cpe.compareAttributes(Part.NA, Part.APPLICATION));
assertFalse(Cpe.compareAttributes(Part.NA, Part.HARDWARE_DEVICE));
assertFalse(Cpe.compareAttributes(Part.NA, Part.OPERATING_SYSTEM));
Expand Down

0 comments on commit 0521b55

Please sign in to comment.