Skip to content

Commit aa2ddf3

Browse files
fix: Database records being lost (fixes intel#3150)
1 parent b825613 commit aa2ddf3

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

cve_bin_tool/cvedb.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def table_schemas(self):
279279
versionEndIncluding TEXT,
280280
versionEndExcluding TEXT,
281281
data_source TEXT,
282-
FOREIGN KEY(cve_number) REFERENCES cve_severity(cve_number)
282+
FOREIGN KEY(cve_number, data_source) REFERENCES cve_severity(cve_number, data_source)
283283
)
284284
"""
285285
exploit_table_create = """
@@ -472,8 +472,8 @@ def populate_db(self) -> None:
472472
break
473473

474474
for cve_data, source_name in self.data:
475-
if source_name != "NVD" and cve_data[0] is not None:
476-
cve_data = self.update_vendors(cve_data)
475+
#if source_name != "NVD" and cve_data[0] is not None:
476+
# cve_data = self.update_vendors(cve_data)
477477

478478
severity_data, affected_data = cve_data
479479

@@ -493,7 +493,7 @@ def populate_db(self) -> None:
493493

494494
def populate_severity(self, severity_data, cursor, data_source):
495495
(insert_severity, _, _, _, _) = self.insert_queries()
496-
del_cve_range = "DELETE from cve_range where CVE_number=?"
496+
del_cve_range = "DELETE from cve_range where CVE_number=? and data_source=?"
497497

498498
for cve in severity_data:
499499
# Check no None values
@@ -532,7 +532,8 @@ def populate_severity(self, severity_data, cursor, data_source):
532532
LOGGER.info(f"Unable to insert data for {data_source} - {e}\n{cve}")
533533

534534
# Delete any old range entries for this CVE_number
535-
cursor.executemany(del_cve_range, [(cve["ID"],) for cve in severity_data])
535+
for cve in severity_data:
536+
cursor.execute(del_cve_range,[cve["ID"], data_source])
536537

537538
def populate_affected(self, affected_data, cursor, data_source):
538539
(_, insert_cve_range, _, _, _) = self.insert_queries()
@@ -689,6 +690,7 @@ def db_open_and_get_cursor(self) -> sqlite3.Cursor:
689690
def db_close(self) -> None:
690691
"""Closes connection to sqlite database."""
691692
if self.connection:
693+
self.connection.commit()
692694
self.connection.close()
693695
self.connection = None
694696

cve_bin_tool/data_sources/nvd_source.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,13 @@ def format_data_api2(self, all_cve_entries):
255255
# return list of versions
256256
affects_list = []
257257
if "configurations" in cve_item:
258-
for node in cve_item["configurations"][0]["nodes"]:
259-
LOGGER.debug(f"Processing {node} for {cve_item['id']}")
260-
affects_list.extend(self.parse_node_api2(node))
261-
if "children" in node:
262-
for child in node["children"]:
263-
affects_list.extend(self.parse_node_api2(child))
258+
for configuration in cve_item["configurations"]:
259+
for node in configuration['nodes']:
260+
self.LOGGER.debug(f"Processing {node} for {cve_item['id']}")
261+
affects_list.extend(self.parse_node_api2(node))
262+
if "children" in node:
263+
for child in node["children"]:
264+
affects_list.extend(self.parse_node_api2(child))
264265
else:
265266
LOGGER.debug(f"No configuration information for {cve_item['id']}")
266267
for affects in affects_list:

0 commit comments

Comments
 (0)