[OE-core] [PATCH RFC CFH][sumo 07/47] cve-check: be idiomatic
Mikko Rapeli
mikko.rapeli at bmw.de
Wed Nov 6 15:37:22 UTC 2019
From: Ross Burton <ross.burton at intel.com>
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 at intel.com>
Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
meta/classes/cve-check.bbclass | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/meta/classes/cve-check.bbclass b/meta/classes/cve-check.bbclass
index 379f712..1e7e8dd 100644
--- a/meta/classes/cve-check.bbclass
+++ b/meta/classes/cve-check.bbclass
@@ -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)
--
1.9.1
More information about the Openembedded-core
mailing list