From 412b72540abcca3dcecf70721878e48af7ca4fa9 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sat, 9 Dec 2017 06:46:05 -0500 Subject: [PATCH] resolve version matching for issue #997 --- .../dependencycheck/data/nvdcve/CveDB.java | 2 +- .../utils/DependencyVersionUtil.java | 21 ++++++++++++- .../dependencycheck-base-suppression.xml | 8 ++++- .../utils/DependencyVersionUtilTest.java | 31 ++++++++++++++++++- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveDB.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveDB.java index f67ffb49d..2b82f59ae 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveDB.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveDB.java @@ -956,7 +956,7 @@ public final class CveDB implements AutoCloseable { } else { versionText = cpe.getVersion(); } - cpeVersion = DependencyVersionUtil.parseVersion(versionText); + cpeVersion = DependencyVersionUtil.parseVersion(versionText, true); } else { cpeVersion = new DependencyVersion("-"); } diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/DependencyVersionUtil.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/DependencyVersionUtil.java index 4bf15f62b..a0ca0aafc 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/DependencyVersionUtil.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/DependencyVersionUtil.java @@ -70,6 +70,25 @@ public final class DependencyVersionUtil { * @return a DependencyVersion containing the version */ public static DependencyVersion parseVersion(String text) { + return parseVersion(text, false); + } + + /** + *

+ * A utility class to extract version numbers from file names (or other + * strings containing version numbers.

+ *
+     * Example:
+     * Give the file name: library-name-1.4.1r2-release.jar
+     * This function would return: 1.4.1.r2
+ * + * @param text the text being analyzed + * @param firstMatchOnly if false and more then one + * version string is found in the given text, null will be returned. + * Otherwise, the first version found will be returned. + * @return a DependencyVersion containing the version + */ + public static DependencyVersion parseVersion(String text, boolean firstMatchOnly) { if (text == null) { return null; } @@ -87,7 +106,7 @@ public final class DependencyVersionUtil { version = matcher.group(); } //throw away the results if there are two things that look like version numbers - if (matcher.find()) { + if (!firstMatchOnly && matcher.find()) { return null; } if (version == null) { diff --git a/dependency-check-core/src/main/resources/dependencycheck-base-suppression.xml b/dependency-check-core/src/main/resources/dependencycheck-base-suppression.xml index 925c36a42..5c82c5362 100644 --- a/dependency-check-core/src/main/resources/dependencycheck-base-suppression.xml +++ b/dependency-check-core/src/main/resources/dependencycheck-base-suppression.xml @@ -958,7 +958,13 @@ ^org\.codehaus\.groovy:groovy-all:.*$ CVE-2016-6497 - +