cve-check: be idiomatic

Instead of generating a series of indexes via range(len(list)), just iterate the
list.

(From OE-Core rev: 27eb839ee651c2d584db42d23bcf5dd764eb33f1)

Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ross Burton
2019-06-24 11:42:55 +01:00
committed by Richard Purdie
parent 3baf4d7fd0
commit db98b1ef48

View File

@@ -170,18 +170,19 @@ def check_cves(d, patched_cves):
cves_unpatched = []
# CVE_PRODUCT can contain more than one product (eg. curl/libcurl)
bpn = d.getVar("CVE_PRODUCT").split()
products = d.getVar("CVE_PRODUCT").split()
# If this has been unset then we're not scanning for CVEs here (for example, image recipes)
if len(bpn) == 0:
if not products:
return ([], [])
pv = d.getVar("CVE_VERSION").split("+git")[0]
cve_whitelist = ast.literal_eval(d.getVar("CVE_CHECK_CVE_WHITELIST"))
# If the recipe has been whitlisted we return empty lists
if d.getVar("PN") in d.getVar("CVE_CHECK_PN_WHITELIST").split():
bb.note("Recipe has been whitelisted, skipping check")
return ([], [])
cve_whitelist = ast.literal_eval(d.getVar("CVE_CHECK_CVE_WHITELIST"))
import sqlite3
db_file = d.getVar("CVE_CHECK_DB_FILE")
conn = sqlite3.connect(db_file)
@@ -190,8 +191,8 @@ def check_cves(d, patched_cves):
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.format(bpn[idx],pv)):
for product in products:
for row in c.execute(query.format(product, pv)):
cve = row[1]
version = row[4]
@@ -200,15 +201,15 @@ def check_cves(d, patched_cves):
except:
discardVersion = True
if pv in cve_whitelist.get(cve,[]):
bb.note("%s-%s has been whitelisted for %s" % (bpn[idx], pv, cve))
if pv in cve_whitelist.get(cve, []):
bb.note("%s-%s has been whitelisted for %s" % (product, 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))
bb.debug(2, "%s-%s is not patched for %s" % (product, pv, cve))
conn.close()
return (list(patched_cves), cves_unpatched)