Skip to content

Commit b12d205

Browse files
author
Ilona Shishov
committed
fix: provide all relevant patch recommendations
Signed-off-by: Ilona Shishov <ishishov@ishishov-thinkpadp1gen7.raanaii.csb>
1 parent 03223ce commit b12d205

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/vuln_analysis/utils/vex/implementations/csaf_generator.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,26 @@ def _get_patched_package(v: dict) -> tuple[str | None, str | None]:
8484
def _build_patch_recommendation(ci: CveIntel, sbom_package_names: set[str] | None) -> str:
8585
"""
8686
Build a patch recommendation from the GHSA data.
87-
- If SBOM provided: return the first matching 'name:first_patched_version' where name is in SBOM, else return "".
87+
- If SBOM provided: return all unique 'name:first_patched_version' pairs where name is in SBOM as list, else return "".
8888
- If no SBOM: return all unique 'name:first_patched_version' pairs as list, else return "".
8989
"""
9090
if not ci or not ci.ghsa or not ci.ghsa.vulnerabilities:
9191
return ""
9292

9393
vulns = ci.ghsa.vulnerabilities
9494

95-
# SBOM
96-
if sbom_package_names is not None:
97-
return next(
98-
(
99-
f"{name}:{patch}"
100-
for v in vulns
101-
for (name, patch) in [(_get_patched_package(v))]
102-
if name and patch and name in sbom_package_names
103-
),
104-
""
105-
)
106-
107-
# No SBOM
10895
name_to_version: dict[str, str] = {}
10996
for v in vulns:
11097
name, patch = _get_patched_package(v)
11198
if not name or not patch:
11299
continue
113-
if name not in name_to_version:
114-
name_to_version[name] = patch
100+
if name in name_to_version:
101+
continue
102+
# If SBOM provided, only include packages that are in the SBOM
103+
if sbom_package_names is not None and name not in sbom_package_names:
104+
continue
105+
name_to_version[name] = patch
106+
115107
if not name_to_version:
116108
return ""
117109
return ", ".join(f"{name}:{patch}" for name, patch in name_to_version.items())

0 commit comments

Comments
 (0)