-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: cvedb metric refactoring #4955
base: main
Are you sure you want to change the base?
Conversation
@22f1001635 What do you think about creating a constant for the metrics data, used in populate_metrics: cve-bin-tool/cve_bin_tool/cvedb.py Lines 645 to 650 in 8f9043a
like: METRICS = [
(UNKNOWN_METRIC_ID, "UNKNOWN"),
(EPSS_METRIC_ID, "EPSS"),
(CVSS_2_METRIC_ID, "CVSS-2"),
(CVSS_3_METRIC_ID, "CVSS-3"),
] and use the new constant in # Check for metrics table data
if table_name == "metrics":
for metrics_id, metrics_name in METRICS:
result = cursor.execute(
"SELECT * FROM metrics WHERE metrics_id=? AND metrics_name", (metrics_id, metrics_name)
)
if not result.fetchone():
schema_latest = False This has the benefit that it's simpler to add additional METRICS in the future like SSVC in example. |
Hi @jloehel , I have made the required changes. Can you take a look and let me know |
Hi :-) Thanks. I have read the code again and I am not sure if the condition is at the right place because self.refresh_cache_and_update_db() gets still only executed if the db does not exist, the db is older than 24 days and the latest_schema is not matching. I think the condition needs to go here: cve-bin-tool/cve_bin_tool/cvedb.py Lines 328 to 336 in 04c47b8
... and you don't need to call populate_metrics again. It gets called in populate_db already. Only the condition when the database gets updated needs to get modified. Sorry, I should have checked this earlier. |
55554fa
to
6b08bef
Compare
@jloehel made changes; take a look and let me know if anything else is needed |
@22f1001635 What do you think about a test case for this scenario?
|
This PR addresses the issue of handling unknown values in metrics by ensuring the UNKNOWN metric is properly initialized and validated in the CVE database. Key changes include:
✔️ Added UNKNOWN_METRIC_ID to populate_metrics to ensure the "UNKNOWN" metric is inserted into the metrics table.
✔️ Enhanced schema validation in latest_schema to check for the existence of the UNKNOWN metric, triggering a refresh if missing.
✔️ Updated metrics during refresh to ensure metrics are re-populated if the schema is outdated.
These changes ensure that the database consistently handles unknown values and maintains up-to-date metrics, improving reliability and correctness.
Fixes
#4812