mirror of
https://git.yoctoproject.org/poky
synced 2026-05-07 16:59:22 +00:00
cve-check: Consider CVE that affects versions with less than operator
In the NVD json CVE feed, affected versions can be strictly matched to a version, but they can also be matched with the operator '<='. Add a new condition in the sqlite query to match affected versions that are defined with the operator '<='. Then use LooseVersion to discard all versions that are not relevant. (From OE-Core rev: 3bf63bc60848d91e90c23f6d854d22b78832aa2d) Signed-off-by: Pierre Le Magourou <pierre.lemagourou@softbankrobotics.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
95f0d11e21
commit
9562ec9c36
@@ -166,6 +166,7 @@ def check_cves(d, patched_cves):
|
||||
Connect to the NVD database and find unpatched cves.
|
||||
"""
|
||||
import ast, csv, tempfile, subprocess, io
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
cves_unpatched = []
|
||||
# CVE_PRODUCT can contain more than one product (eg. curl/libcurl)
|
||||
@@ -186,14 +187,25 @@ def check_cves(d, patched_cves):
|
||||
conn = sqlite3.connect(db_file)
|
||||
c = conn.cursor()
|
||||
|
||||
query = "SELECT * FROM PRODUCTS WHERE PRODUCT IS '%s' AND VERSION IS '%s';"
|
||||
query = """SELECT * FROM PRODUCTS WHERE
|
||||
(PRODUCT IS '{0}' AND VERSION = '{1}' AND OPERATOR IS '=') OR
|
||||
(PRODUCT IS '{0}' AND OPERATOR IS '<=');"""
|
||||
for idx in range(len(bpn)):
|
||||
for row in c.execute(query % (bpn[idx],pv)):
|
||||
for row in c.execute(query.format(bpn[idx],pv)):
|
||||
cve = row[1]
|
||||
version = row[4]
|
||||
|
||||
try:
|
||||
discardVersion = LooseVersion(version) < LooseVersion(pv)
|
||||
except:
|
||||
discardVersion = True
|
||||
|
||||
if pv in cve_whitelist.get(cve,[]):
|
||||
bb.note("%s-%s has been whitelisted for %s" % (bpn[idx], pv, cve))
|
||||
elif cve in patched_cves:
|
||||
bb.note("%s has been patched" % (cve))
|
||||
elif discardVersion:
|
||||
bb.debug(2, "Do not consider version %s " % (version))
|
||||
else:
|
||||
cves_unpatched.append(cve)
|
||||
bb.debug(2, "%s-%s is not patched for %s" % (bpn[idx], pv, cve))
|
||||
|
||||
Reference in New Issue
Block a user