Skip to content

Commit 7fbdf42

Browse files
author
Vadim Bogulean
committed
Fix search for CVE by ID and 'bad' CPE23 value
1 parent ffb40d2 commit 7fbdf42

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/common/search.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,20 @@ def search_cves(appctx: ApplicationContext, opts: SearchOptions):
4242
query = session.query(cve_table)
4343

4444
# filter by the cve IDS, either directly specified in the search options
45-
cve_ids = []
46-
if opts.cveId: cve_ids.extend(opts.cveId)
47-
# or via the cpe 2.3
48-
if opts.cpeName: cve_ids.extend(search_cves_by_cpes(appctx, opts))
45+
if opts.cveId:
46+
cve_ids = list(map(lambda cve_id: cve_id.upper(), set(cve_ids)))
47+
query = query.filter(cve_table.vuln_id.in_(cve_ids))
4948

50-
# filter by the cve IDs
51-
cve_ids = list(map(lambda cve_id: cve_id.upper(), set(cve_ids)))
52-
if cve_ids: query = query.filter(cve_table.vuln_id.in_(cve_ids))
49+
# or via the cpe 2.3
50+
if opts.cpeName:
51+
cve_ids = search_cves_by_cpes(appctx, opts)
52+
# if we got CVE IDs from the CPE 2.3 search, we need to filter the results
53+
if cve_ids:
54+
query = query.filter(cve_table.vuln_id.in_(cve_ids))
55+
# otherwise it means that there are no CVE IDs from the CPE 2.3 search
56+
# thus the query needs to return no records
57+
else:
58+
query = query.filter(1 == 0)
5359

5460
# filter by the keyword search (regex)
5561
if opts.keywordSearch:

0 commit comments

Comments
 (0)