summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@arm.com>2022-08-26 18:35:47 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-09-12 08:41:47 +0100
commit4384b8a13ae515e6d6b2a8375a9fc1a11e5b6e76 (patch)
tree3ece650c9f318b963497f058ccc9eee001d50a32 /meta/classes
parent8856232de42099654a5d2cc8bc422d1e430a0ab4 (diff)
downloadpoky-4384b8a13ae515e6d6b2a8375a9fc1a11e5b6e76.tar.gz
cve-check: close cursors as soon as possible
We can have multiple processes reading the database at the same time, and cursors only release their locks when they're garbage collected. This might be the cause of random sqlite errors on the autobuilder, so explicitly close the cursors when we're done with them. (From OE-Core rev: 90917cadeb7201e56c74294e9156fe899d5455d7) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> (cherry picked from commit 5d2e90e4a58217a943ec21140bc2ecdd4357a98a) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/cve-check.bbclass13
1 files changed, 9 insertions, 4 deletions
diff --git a/meta/classes/cve-check.bbclass b/meta/classes/cve-check.bbclass
index b751c986ef..16466586a7 100644
--- a/meta/classes/cve-check.bbclass
+++ b/meta/classes/cve-check.bbclass
@@ -291,7 +291,8 @@ def check_cves(d, patched_cves):
291 vendor = "%" 291 vendor = "%"
292 292
293 # Find all relevant CVE IDs. 293 # Find all relevant CVE IDs.
294 for cverow in conn.execute("SELECT DISTINCT ID FROM PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor)): 294 cve_cursor = conn.execute("SELECT DISTINCT ID FROM PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor))
295 for cverow in cve_cursor:
295 cve = cverow[0] 296 cve = cverow[0]
296 297
297 if cve in cve_ignore: 298 if cve in cve_ignore:
@@ -310,7 +311,8 @@ def check_cves(d, patched_cves):
310 vulnerable = False 311 vulnerable = False
311 ignored = False 312 ignored = False
312 313
313 for row in conn.execute("SELECT * FROM PRODUCTS WHERE ID IS ? AND PRODUCT IS ? AND VENDOR LIKE ?", (cve, product, vendor)): 314 product_cursor = conn.execute("SELECT * FROM PRODUCTS WHERE ID IS ? AND PRODUCT IS ? AND VENDOR LIKE ?", (cve, product, vendor))
315 for row in product_cursor:
314 (_, _, _, version_start, operator_start, version_end, operator_end) = row 316 (_, _, _, version_start, operator_start, version_end, operator_end) = row
315 #bb.debug(2, "Evaluating row " + str(row)) 317 #bb.debug(2, "Evaluating row " + str(row))
316 if cve in cve_ignore: 318 if cve in cve_ignore:
@@ -354,10 +356,12 @@ def check_cves(d, patched_cves):
354 bb.note("%s-%s is vulnerable to %s" % (pn, real_pv, cve)) 356 bb.note("%s-%s is vulnerable to %s" % (pn, real_pv, cve))
355 cves_unpatched.append(cve) 357 cves_unpatched.append(cve)
356 break 358 break
359 product_cursor.close()
357 360
358 if not vulnerable: 361 if not vulnerable:
359 bb.note("%s-%s is not vulnerable to %s" % (pn, real_pv, cve)) 362 bb.note("%s-%s is not vulnerable to %s" % (pn, real_pv, cve))
360 patched_cves.add(cve) 363 patched_cves.add(cve)
364 cve_cursor.close()
361 365
362 if not cves_in_product: 366 if not cves_in_product:
363 bb.note("No CVE records found for product %s, pn %s" % (product, pn)) 367 bb.note("No CVE records found for product %s, pn %s" % (product, pn))
@@ -382,14 +386,15 @@ def get_cve_info(d, cves):
382 conn = sqlite3.connect(db_file, uri=True) 386 conn = sqlite3.connect(db_file, uri=True)
383 387
384 for cve in cves: 388 for cve in cves:
385 for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)): 389 cursor = conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,))
390 for row in cursor:
386 cve_data[row[0]] = {} 391 cve_data[row[0]] = {}
387 cve_data[row[0]]["summary"] = row[1] 392 cve_data[row[0]]["summary"] = row[1]
388 cve_data[row[0]]["scorev2"] = row[2] 393 cve_data[row[0]]["scorev2"] = row[2]
389 cve_data[row[0]]["scorev3"] = row[3] 394 cve_data[row[0]]["scorev3"] = row[3]
390 cve_data[row[0]]["modified"] = row[4] 395 cve_data[row[0]]["modified"] = row[4]
391 cve_data[row[0]]["vector"] = row[5] 396 cve_data[row[0]]["vector"] = row[5]
392 397 cursor.close()
393 conn.close() 398 conn.close()
394 return cve_data 399 return cve_data
395 400