diff mbox series

cve-check: be idiomatic

Message ID 20190624104255.5544-1-ross.burton@intel.com
State Accepted
Commit 27eb839ee651c2d584db42d23bcf5dd764eb33f1
Headers show
Series cve-check: be idiomatic | expand

Commit Message

Ross Burton June 24, 2019, 10:42 a.m. UTC
Instead of generating a series of indexes via range(len(list)), just iterate the
list.

Signed-off-by: Ross Burton <ross.burton@intel.com>

---
 meta/classes/cve-check.bbclass | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

-- 
2.11.0

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
diff mbox series

Patch

diff --git a/meta/classes/cve-check.bbclass b/meta/classes/cve-check.bbclass
index 379f7121cc1..1e7e8dd4413 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)