Skip to content

feat: Add Affected versions list when no range is available #5047

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cve_bin_tool/cve_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):

cve_list = list(map(lambda x: x[0], self.cursor.fetchall()))

for cve_number in cve_list:
query = """
SELECT version FROM cve_range
WHERE CVE_number=? AND versionStartIncluding='' AND versionStartExcluding='' AND versionEndIncluding='' AND versionEndExcluding=''
"""
self.cursor.execute(query, [cve_number])
affected_versions = list(set(map(lambda x: x[0], self.cursor.fetchall())))
self.all_cve_version_info[cve_number] = VersionInfo(
"", "", "", "", affected_versions
)

# Check for any ranges
query = """
SELECT
Expand Down Expand Up @@ -208,6 +219,7 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
start_excluding=version_start_excluding,
end_including=version_end_including,
end_excluding=version_end_excluding,
version_list=[],
)

product_info_data: CVEData | None = self.all_cve_data.get(product_info)
Expand Down
2 changes: 1 addition & 1 deletion cve_bin_tool/output_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def output_pdf(
except (
KeyError
): # TODO: handle 'UNKNOWN' and some cves more cleanly
version_info = VersionInfo("", "", "", "")
version_info = VersionInfo("", "", "", "", [])
cve_by_remarks[cve.remarks][-1].update(
{"affected_versions": format_version_range(version_info)}
)
Expand Down
2 changes: 1 addition & 1 deletion cve_bin_tool/output_engine/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _output_console_nowrap(
try:
version_info = all_cve_version_info[cve.cve_number]
except KeyError: # TODO: handle 'UNKNOWN' and some cves more cleanly
version_info = VersionInfo("", "", "", "")
version_info = VersionInfo("", "", "", "", [])
cve_by_remarks[cve.remarks][-1].update(
{"affected_versions": format_version_range(version_info)}
)
Expand Down
8 changes: 6 additions & 2 deletions cve_bin_tool/output_engine/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def format_version_range(version_info: VersionInfo) -> str:
Reference for Interval terminologies: https://en.wikipedia.org/wiki/Interval_(mathematics)
"""

(start_including, start_excluding, end_including, end_excluding) = version_info
(start_including, start_excluding, end_including, end_excluding, version_list) = (
version_info
)
if start_including and end_including:
return f"[{start_including} - {end_including}]"
if start_including and end_excluding:
Expand All @@ -140,6 +142,8 @@ def format_version_range(version_info: VersionInfo) -> str:
return f"<= {end_including}"
if end_excluding:
return f"< {end_excluding}"
if version_list:
return "list: " + ", ".join(version_list)
return "-"


Expand Down Expand Up @@ -225,7 +229,7 @@ def format_output(
):
version_info = all_cve_version_info[cve.cve_number]
else: # TODO: handle 'UNKNOWN' and some cves more cleanly
version_info = VersionInfo("", "", "", "")
version_info = VersionInfo("", "", "", "", [])
details["affected_versions"] = format_version_range(version_info)
formatted_output.append(details)

Expand Down
1 change: 1 addition & 0 deletions cve_bin_tool/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class VersionInfo(NamedTuple):
start_excluding: str
end_including: str
end_excluding: str
version_list: list[str]


class CVEData(DefaultDict[str, Union[List[CVE], Set[str]]]):
Expand Down
18 changes: 9 additions & 9 deletions test/test_output_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,15 @@ class TestOutputEngine(unittest.TestCase):
}

MOCK_ALL_CVE_VERSION_INFO = {
"UNKNOWN": VersionInfo("", "", "", ""),
"CVE-9999-0001": VersionInfo("0.9.0", "", "1.2.0", ""),
"CVE-9999-0002": VersionInfo("0.9.0", "", "", "1.2.0"),
"CVE-9999-0003": VersionInfo("", "0.9.0", "1.2.0", ""),
"CVE-9999-0004": VersionInfo("", "0.9.0", "", "1.2.0"),
"CVE-9999-0005": VersionInfo("0.9.0", "", "", ""),
"CVE-9999-0006": VersionInfo("", "0.9.0", "", ""),
"CVE-9999-0007": VersionInfo("", "", "1.2.0", ""),
"CVE-9999-0008": VersionInfo("", "", "", "1.2.0"),
"UNKNOWN": VersionInfo("", "", "", "", []),
"CVE-9999-0001": VersionInfo("0.9.0", "", "1.2.0", "", []),
"CVE-9999-0002": VersionInfo("0.9.0", "", "", "1.2.0", []),
"CVE-9999-0003": VersionInfo("", "0.9.0", "1.2.0", "", []),
"CVE-9999-0004": VersionInfo("", "0.9.0", "", "1.2.0", []),
"CVE-9999-0005": VersionInfo("0.9.0", "", "", "", []),
"CVE-9999-0006": VersionInfo("", "0.9.0", "", "", []),
"CVE-9999-0007": VersionInfo("", "", "1.2.0", "", []),
"CVE-9999-0008": VersionInfo("", "", "", "1.2.0", []),
}

MOCK_ORGANIZED_PARAMETERS = {
Expand Down
Loading