Skip to content

Commit b6a1e5e

Browse files
Merge pull request #5195 from joydeep049/noscan-OPengine-update
feat: OutputEngine updates for no-scan
2 parents 079bc77 + 8c0badf commit b6a1e5e

File tree

5 files changed

+188
-129
lines changed

5 files changed

+188
-129
lines changed

cve_bin_tool/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import textwrap
3333
import time
3434
from collections import ChainMap
35+
from datetime import datetime
3536
from pathlib import Path
3637

3738
from cve_bin_tool.available_fix import (
@@ -1091,6 +1092,7 @@ def main(argv=None):
10911092
check_exploits=args["exploits"],
10921093
exploits_list=cvedb_orig.get_exploits_list(),
10931094
disabled_sources=disabled_sources,
1095+
no_scan=args["no_scan"],
10941096
) as cve_scanner:
10951097
triage_data: TriageData
10961098
total_files: int = 0
@@ -1267,7 +1269,9 @@ def main(argv=None):
12671269
scanned_dir=args["directory"],
12681270
filename=args["output_file"],
12691271
themes_dir=args["html_theme"],
1270-
time_of_last_update=cvedb_orig.time_of_last_update,
1272+
time_of_last_update=(
1273+
cvedb_orig.time_of_last_update if cvedb_orig else datetime.now()
1274+
),
12711275
tag=args["tag"],
12721276
products_with_cve=cve_scanner.products_with_cve,
12731277
products_without_cve=cve_scanner.products_without_cve,
@@ -1290,6 +1294,7 @@ def main(argv=None):
12901294
sbom_root=sbom_root,
12911295
strip_scan_dir=args["strip_scan_dir"],
12921296
offline=args["offline"],
1297+
no_scan=args["no_scan"],
12931298
)
12941299

12951300
if not args["quiet"]:

cve_bin_tool/cve_scanner.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,22 @@ def __init__(
4646
check_exploits: bool = False,
4747
exploits_list: List[str] = [],
4848
disabled_sources: List[str] = [],
49+
no_scan: bool = False,
4950
):
50-
self.logger = logger or LOGGER.getChild(self.__class__.__name__)
51-
self.error_mode = error_mode
5251
self.score = score
5352
self.check_metrics = check_metrics
5453
self.epss_percentile = epss_percentile
5554
self.epss_probability = epss_probability
56-
self.products_with_cve = 0
57-
self.products_without_cve = 0
58-
self.all_cve_data = defaultdict(CVEData)
59-
self.all_cve_version_info = dict()
55+
self.logger = logger or LOGGER.getChild(self.__class__.__name__)
56+
self.error_mode = error_mode
6057
self.check_exploits = check_exploits
6158
self.exploits_list = exploits_list
6259
self.disabled_sources = disabled_sources
60+
self.no_scan = no_scan
61+
self.products_with_cve = 0
62+
self.products_without_cve = 0
63+
self.all_cve_data = defaultdict(lambda: {"cves": [], "paths": set()})
64+
self.all_cve_version_info = dict()
6365
self.all_product_data = dict()
6466

6567
def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
@@ -74,6 +76,21 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
7476
if self.score > 10 or self.epss_probability > 1.0 or self.epss_percentile > 1.0:
7577
return
7678

79+
# Handle no-scan mode
80+
if self.no_scan:
81+
# In no-scan mode, just populate the product data without CVE scanning
82+
if product_info not in self.all_product_data:
83+
self.logger.debug(f"Add product {product_info} (no-scan mode)")
84+
self.all_product_data[product_info] = 0
85+
86+
# Also populate all_cve_data with empty CVE list and paths
87+
if product_info not in self.all_cve_data:
88+
self.all_cve_data[product_info] = {"cves": [], "paths": set()}
89+
90+
# Update paths
91+
self.all_cve_data[product_info]["paths"] |= set(triage_data["paths"])
92+
return
93+
7794
if product_info.vendor == "UNKNOWN":
7895
# Add product
7996
if product_info not in self.all_product_data:
@@ -298,7 +315,7 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
298315
self.epss_percentile,
299316
self.epss_probability,
300317
)
301-
# row_dict doesnt have metric as key. As it based on result from query on
318+
# row_dict doesn't have metric as key. As it based on result from query on
302319
# cve_severity table declaring row_dict[metric]
303320
row_dict["metric"] = {}
304321
# looping for result of query for metrics.
@@ -481,9 +498,10 @@ def __enter__(self):
481498
Returns:
482499
CVEScanner: The instance of the CVEScanner with an active database connection.
483500
"""
484-
self.connection = sqlite3.connect(self.dbname)
485-
self.connection.row_factory = sqlite3.Row
486-
self.cursor = self.connection.cursor()
501+
if not self.no_scan:
502+
self.connection = sqlite3.connect(self.dbname)
503+
self.connection.row_factory = sqlite3.Row
504+
self.cursor = self.connection.cursor()
487505
return self
488506

489507
def __exit__(self, exc_type, exc_val, exc_tb):
@@ -498,5 +516,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
498516
Returns:
499517
None
500518
"""
501-
self.cursor.close()
502-
self.connection.close()
519+
if not self.no_scan and hasattr(self, "cursor") and hasattr(self, "connection"):
520+
self.cursor.close()
521+
self.connection.close()

cve_bin_tool/output_engine/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def output_pdf(
621621

622622
class OutputEngine:
623623
"""
624-
Class represention of OutputEngine
624+
Class representation of OutputEngine
625625
Attributes:
626626
all_cve_data (dict[ProductInfo, CVEData])
627627
scanned_dir (str)
@@ -693,6 +693,7 @@ def __init__(
693693
vex_product_info: dict[str, str] = {},
694694
offline: bool = False,
695695
organized_arguements: dict = None,
696+
no_scan: bool = False,
696697
):
697698
"""Constructor for OutputEngine class."""
698699
self.logger = logger or LOGGER.getChild(self.__class__.__name__)
@@ -726,6 +727,7 @@ def __init__(
726727
self.vex_type = vex_type
727728
self.vex_product_info = vex_product_info
728729
self.vex_filename = vex_filename
730+
self.no_scan = no_scan
729731

730732
def output_cves(self, outfile, output_type="console"):
731733
"""Output a list of CVEs
@@ -812,6 +814,7 @@ def output_cves(self, outfile, output_type="console"):
812814
self.offline,
813815
None,
814816
outfile,
817+
self.no_scan,
815818
)
816819

817820
if isinstance(self.append, str):

0 commit comments

Comments
 (0)