Skip to content

Commit 6f9669f

Browse files
fix: CVEs from multiple sources missing (Fixes #2418) (#2421)
* Fixes #2418
1 parent b17a185 commit 6f9669f

File tree

7 files changed

+61
-45
lines changed

7 files changed

+61
-45
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,6 @@ This data source contains CVEs pertaining to RedHat Products.
304304

305305
Access to the data is subject to [Legal Notice](https://access.redhat.com/documentation/en-us/red_hat_security_data_api/1.0/html/red_hat_security_data_api/legal-notice).
306306

307-
### [RedHat Security Database](https://access.redhat.com/security/data) (REDHAT)
308-
309-
This data source contains CVEs pertaining to RedHat Products.
310-
311-
Access to the data is subject to [Legal Notice](https://access.redhat.com/documentation/en-us/red_hat_security_data_api/1.0/html/red_hat_security_data_api/legal-notice).
312-
313307
## Binary checker list
314308

315309
The following checkers are available for finding components in binary files:

cve_bin_tool/cve_scanner.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
222222
# Skipping CVEs from disabled data sources
223223
if row["data_source"] in self.disabled_sources:
224224
continue
225+
226+
# To avoid duplicate reporting, skip reporting CVE if already reported
227+
duplicate_found = False
228+
for c in cves:
229+
if c.cve_number == row["cve_number"]:
230+
self.logger.debug(
231+
f"{row['cve_number']} already reported from {c.data_source}"
232+
)
233+
duplicate_found = True
234+
break
235+
236+
if duplicate_found:
237+
continue
238+
225239
triage = triage_data.get(row["cve_number"]) or triage_data.get(
226240
"default"
227241
)

cve_bin_tool/cvedb.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def table_schemas(self):
226226
cvss_vector TEXT,
227227
data_source TEXT,
228228
last_modified TIMESTAMP,
229-
PRIMARY KEY(cve_number)
229+
PRIMARY KEY(cve_number, data_source)
230230
)
231231
"""
232232
version_range_create = """
@@ -239,6 +239,7 @@ def table_schemas(self):
239239
versionStartExcluding TEXT,
240240
versionEndIncluding TEXT,
241241
versionEndExcluding TEXT,
242+
data_source TEXT,
242243
FOREIGN KEY(cve_number) REFERENCES cve_severity(cve_number)
243244
)
244245
"""
@@ -295,6 +296,7 @@ def populate_db(self) -> None:
295296
self.populate_affected(
296297
affected_data,
297298
cursor,
299+
data_source=source_name,
298300
)
299301
if self.connection is not None:
300302
self.connection.commit()
@@ -357,7 +359,7 @@ def populate_severity(self, severity_data, cursor, data_source):
357359
# Delete any old range entries for this CVE_number
358360
cursor.executemany(del_cve_range, [(cve["ID"],) for cve in severity_data])
359361

360-
def populate_affected(self, affected_data, cursor):
362+
def populate_affected(self, affected_data, cursor, data_source):
361363

362364
insert_cve_range = """
363365
INSERT or REPLACE INTO cve_range(
@@ -368,26 +370,31 @@ def populate_affected(self, affected_data, cursor):
368370
versionStartIncluding,
369371
versionStartExcluding,
370372
versionEndIncluding,
371-
versionEndExcluding
372-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
373+
versionEndExcluding,
374+
data_source
375+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
373376
"""
374377

375-
cursor.executemany(
376-
insert_cve_range,
377-
[
378-
(
379-
affected["cve_id"],
380-
affected["vendor"],
381-
affected["product"],
382-
affected["version"],
383-
affected["versionStartIncluding"],
384-
affected["versionStartExcluding"],
385-
affected["versionEndIncluding"],
386-
affected["versionEndExcluding"],
387-
)
388-
for affected in affected_data
389-
],
390-
)
378+
try:
379+
cursor.executemany(
380+
insert_cve_range,
381+
[
382+
(
383+
affected["cve_id"],
384+
affected["vendor"],
385+
affected["product"],
386+
affected["version"],
387+
affected["versionStartIncluding"],
388+
affected["versionStartExcluding"],
389+
affected["versionEndIncluding"],
390+
affected["versionEndExcluding"],
391+
data_source,
392+
)
393+
for affected in affected_data
394+
],
395+
)
396+
except Exception as e:
397+
LOGGER.info(f"Unable to insert data for {data_source} - {e}")
391398

392399
def clear_cached_data(self) -> None:
393400
self.create_cache_backup()

cve_bin_tool/data_sources/gad_source.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ async def fetch_cves(self):
8888

8989
if not Path(self.gad_path).exists():
9090
Path(self.gad_path).mkdir()
91+
# As no data, force full update
92+
self.incremental_update = False
9193

9294
if not self.session:
9395
connector = aiohttp.TCPConnector(limit_per_host=19)
@@ -184,7 +186,7 @@ def parse_range_string(self, range_string):
184186
"versionEndExcluding": "",
185187
}
186188

187-
versions = version_string.split(",")
189+
versions = version_string.replace(",", " ").split(" ")
188190

189191
for version in versions:
190192
if ">=" in version:

cve_bin_tool/data_sources/osv_source.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ async def fetch_cves(self):
161161

162162
if not Path(self.osv_path).exists():
163163
Path(self.osv_path).mkdir()
164+
# As no data, force full update
165+
self.incremental_update = False
164166

165167
if not self.session:
166168
connector = aiohttp.TCPConnector(limit_per_host=19)

cve_bin_tool/data_sources/redhat_source.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def format_data(self, all_cve_entries):
149149
4: "MEDIUM",
150150
5: "MEDIUM",
151151
6: "MEDIUM",
152-
7: "MEDIUM",
152+
7: "HIGH",
153153
8: "HIGH",
154154
9: "CRITICAL",
155155
10: "CRITICAL",
@@ -222,25 +222,23 @@ def format_data(self, all_cve_entries):
222222
s = package.split(":")
223223
product = s[0]
224224
version = s[1]
225+
affected = {
226+
"cve_id": cve_id,
227+
"vendor": "redhat",
228+
"product": product,
229+
"version": version,
230+
"versionStartIncluding": "",
231+
"versionStartExcluding": "",
232+
"versionEndIncluding": "",
233+
"versionEndExcluding": "",
234+
}
235+
affected_data.append(affected)
236+
if cve_to_write:
237+
severity_data.append(cve)
238+
cve_to_write = False
225239
else:
226240
# Version not specified
227241
LOGGER.debug(f"{cve_id} : Version not specified for {package}")
228-
product = package
229-
version = "*"
230-
affected = {
231-
"cve_id": cve_id,
232-
"vendor": "redhat",
233-
"product": product,
234-
"version": version,
235-
"versionStartIncluding": "",
236-
"versionStartExcluding": "",
237-
"versionEndIncluding": "",
238-
"versionEndExcluding": "",
239-
}
240-
affected_data.append(affected)
241-
if cve_to_write:
242-
severity_data.append(cve)
243-
cve_to_write = False
244242
except Exception as e:
245243
LOGGER.debug(e)
246244
LOGGER.debug(f"{cve_id} : Affected {package}")

test/test_requirements.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ def test_requirements():
150150
output_json = json.load(f)
151151
for entry in output_json:
152152
assert entry["remarks"] in ["Mitigated", "Ignored"]
153-
154153
# Disabled until we fix how ignored/mitigated issues are listed
155154
# See https://github.com/intel/cve-bin-tool/issues/1752
156155
# assert (

0 commit comments

Comments
 (0)