Skip to content

Commit 88d68f8

Browse files
Improve reporting of empty CVE database (#918) (#928)
1 parent b53faf4 commit 88d68f8

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

cve_bin_tool/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
InsufficientArgs,
3333
EmptyCache,
3434
ErrorMode,
35+
CVEDataMissing,
3536
)
3637
from .input_engine import InputEngine, TriageData
3738
from .log import LOGGER
@@ -254,6 +255,11 @@ def main(argv=None):
254255
with ErrorHandler(mode=error_mode, logger=LOGGER):
255256
raise EmptyCache(cvedb_orig.cachedir)
256257

258+
# CVE Database validation
259+
if not cvedb_orig.check_cve_entries():
260+
with ErrorHandler(mode=error_mode, logger=LOGGER):
261+
raise CVEDataMissing("No data in CVE Database")
262+
257263
# Input validation
258264
if not args["directory"] and not args["input_file"]:
259265
parser.print_usage()

cve_bin_tool/cvedb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,18 @@ def latest_schema(self, cursor):
266266
schema_latest = True
267267
return schema_latest
268268

269+
def check_cve_entries(self):
270+
""" Report if database has some CVE entries """
271+
self.db_open()
272+
cursor = self.connection.cursor()
273+
cve_entries_check = "SELECT COUNT(*) FROM cve_severity"
274+
cursor.execute(cve_entries_check)
275+
# Find number of entries
276+
cve_entries = cursor.fetchone()[0]
277+
self.LOGGER.info(f"There are {cve_entries} CVE entries in the database")
278+
self.db_close()
279+
return cve_entries > 0
280+
269281
def init_database(self):
270282
""" Initialize db tables used for storing cve/version data """
271283
self.db_open()

cve_bin_tool/error_handler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class CVEDataForCurlVersionNotInCache(Exception):
4444
"""
4545

4646

47+
class CVEDataMissing(Exception):
48+
"""
49+
Raised when no CVE data is present in the database.
50+
"""
51+
52+
4753
class AttemptedToWriteOutsideCachedir(Exception):
4854
"""
4955
Raised if we attempted to write to a file that would have been outside the
@@ -145,4 +151,5 @@ def __exit__(self, exc_type, exc_val, exc_tb):
145151
ExtractionFailed: -12,
146152
UnknownArchiveType: -13,
147153
UnknownConfigType: -14,
154+
CVEDataMissing: -15,
148155
}

0 commit comments

Comments
 (0)