Skip to content
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

fix: KeyError in format_data function #3452

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Changes from 4 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
25 changes: 14 additions & 11 deletions cve_bin_tool/data_sources/osv_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,18 @@ def format_data(self, all_cve_entries):

severity_data.append(cve)

for package in cve_item["affected"]:
product = package["package"]["name"]
for package_data in cve_item.get("affected", []):
package = package_data.get("package", {})
if not package:
continue

product = package.get("name")
vendor = (
"unknown" # OSV Schema does not provide vendor names for packages
)
if (
"github.com/" in product
): # if package name is of format github.com/xxxx/yyyy xxxx can be vendor name and yyyy is package name
vendor = product.split("/")[-2] # trying to guess vendor name
"unknown" # OSV Schema does not provide vendor names for packages
terriko marked this conversation as resolved.
Show resolved Hide resolved
)
terriko marked this conversation as resolved.
Show resolved Hide resolved

if product.startswith("github.com/"):
Dismissed Show dismissed Hide dismissed
vendor = product.split("/")[-2]
product = product.split("/")[-1]

affected = {
Expand All @@ -315,12 +318,12 @@ def format_data(self, all_cve_entries):
}

events = None
for ranges in package.get("ranges", []):
for ranges in package_data.get("ranges", []):
if ranges["type"] == "SEMVER":
events = ranges["events"]

if events is None and "versions" in package:
versions = package["versions"]
if events is None and "versions" in package_data:
versions = package_data["versions"]

if versions == []:
continue
Expand Down
Loading