Skip to content

Commit ace0ca0

Browse files
author
Prabhu Subramanian
committed
Improved version matching logic
1 parent c769c84 commit ace0ca0

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="appthreat-vulnerability-db",
8-
version="1.6.5",
8+
version="1.6.6",
99
author="Team AppThreat",
1010
author_email="cloud@appthreat.com",
1111
description="AppThreat's vulnerability database and package search library with a built-in file based storage. CVE, GitHub, npm are the primary sources of vulnerabilities.",

test/test_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ def test_version_build_compare():
177177
res = utils.version_compare("1.3.0", "1.2.0-beta", "1.3.2.0")
178178
assert res
179179

180+
def test_version_build_diff_compare():
181+
res = utils.version_compare("7.0.0", "*", "*", None, "2020-04-23t00-58-49z")
182+
assert not res
183+
res = utils.version_compare("7.0.0", "*", "*", None, "2018-05-16t23-35-33z")
184+
assert not res
185+
res = utils.version_compare("7.0.0", "2018-05-16t23-35-33z", "2020-04-23t00-58-49z")
186+
assert not res
187+
res = utils.version_compare("7.0.0", None, "2020-04-23t00-58-49z", "2020-04-23t00-58-49z", None)
188+
assert not res
189+
res = utils.version_compare("7.0.0", None, "2018-05-16t23-35-33z", "2018-05-16t23-35-33z", None)
190+
assert not res
191+
res = utils.version_compare("7.0.0", "*", None, "2020-04-23t00-58-49z", None)
192+
assert not res
193+
res = utils.version_compare("7.0.0", "*", None, "2018-05-16t23-35-33z", None)
194+
assert not res
195+
180196

181197
def test_parse_uri():
182198
vendor, package, version = utils.parse_cpe(

vdb/lib/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ def version_compare(
340340
is_max_exclude = True
341341
if not min_version:
342342
min_version = "0"
343+
# If compare_ver is semver compatible and min_version is * then max_version should be semver compatible
344+
if (
345+
compare_ver
346+
and VersionInfo.isvalid(compare_ver)
347+
and (not min_version or min_version == "*")
348+
and not VersionInfo.isvalid(max_version)
349+
):
350+
return False
343351
# Perform semver match once we have all the required versions
344352
if compare_ver and min_version and max_version:
345353
if semver_compatible(compare_ver, min_version, max_version):

0 commit comments

Comments
 (0)