Skip to content

Commit

Permalink
Merge pull request #4612 from nscuro/backport-pr-4610
Browse files Browse the repository at this point in the history
  • Loading branch information
nscuro authored Feb 3, 2025
2 parents 01431d2 + 0b2da11 commit efad42c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ private Boolean maybeMatchCpe(final VulnerableSoftware vs, final Cpe targetCpe,
* Ported from Dependency-Check v5.2.1
*/
private static boolean compareVersions(VulnerableSoftware vs, String targetVersion) {
// Modified from original by @nscuro.
// Special cases for CPE matching of ANY (*) and NA (*) versions.
// These don't make sense to use for version range comparison and
// can be dealt with upfront based on the matching documentation:
// https://nvlpubs.nist.gov/nistpubs/Legacy/IR/nistir7696.pdf
if ("*".equals(targetVersion)) {
// | No. | Source A-V | Target A-V | Relation |
// | :-- | :------------- | :--------- | :------- |
// | 1 | ANY | ANY | EQUAL |
// | 5 | NA | ANY | SUBSET |
// | 13 | i | ANY | SUBSET |
// | 15 | m + wild cards | ANY | SUBSET |
return true;
} else if ("-".equals(targetVersion)) {
// | No. | Source A-V | Target A-V | Relation |
// | :-- | :------------- | :--------- | :------- |
// | 2 | ANY | NA | SUPERSET |
// | 6 | NA | NA | EQUAL |
// | 12 | i | NA | DISJOINT |
// | 16 | m + wild cards | NA | DISJOINT |
return "*".equals(vs.getVersion()) || "-".equals(vs.getVersion());
}

//if any of the four conditions will be evaluated - then true;
boolean result = (vs.getVersionEndExcluding() != null && !vs.getVersionEndExcluding().isEmpty())
|| (vs.getVersionStartExcluding() != null && !vs.getVersionStartExcluding().isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,16 @@ public static Collection<Object[]> parameters() {
// Scenario: "vendor" of source is i, "product" of source is ANY, "vendor" of target is ANY, "product" of target is i
// We consider mixed SUBSET and SUPERSET relations in "vendor" and "product" attributes to be ambiguous and treat them as no-match
// Table No.: 3, 13
{"cpe:2.3:a:pascom_cloud_phone_system:*:*:*:*:*:*:*:*:*", WITHOUT_RANGE, DOES_NOT_MATCH, "cpe:2.3:a:*:util-linux-setarch:2.37.4:*:*:*:*:*:*:*"}
{"cpe:2.3:a:pascom_cloud_phone_system:*:*:*:*:*:*:*:*:*", WITHOUT_RANGE, DOES_NOT_MATCH, "cpe:2.3:a:*:util-linux-setarch:2.37.4:*:*:*:*:*:*:*"},
// ---
// Issue: https://github.com/DependencyTrack/dependency-track/issues/4609
// Scenario: "version" of source and target are ANY -> EQUAL.
// A version range is available but doesn't make sense to use since the target version is already ANY.
// Table No.: 1
{"cpe:2.3:a:zlib:zlib:*:*:*:*:*:*:*:*", withRange().havingStartIncluding("1.2.0").havingEndExcluding("1.2.9"), MATCHES, "cpe:2.3:a:zlib:zlib:*:*:*:*:*:*:*:*"},
// Scenario: Same as above, but "version" of target is NA -> SUPERSET.
// Table No.: 2
{"cpe:2.3:a:zlib:zlib:*:*:*:*:*:*:*:*", withRange().havingStartIncluding("1.2.0").havingEndExcluding("1.2.9"), MATCHES, "cpe:2.3:a:zlib:zlib:-:*:*:*:*:*:*:*"}
});
}

Expand Down

0 comments on commit efad42c

Please sign in to comment.