Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPE: Fix false negative on part comparison #180

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading