Skip to content
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
22 changes: 19 additions & 3 deletions dojo/tools/govulncheck/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,23 @@ def get_affected_version(self, data, osv_id):
def get_findings(self, scan_file, test):
findings = []
try:
data = json.load(scan_file)
try:
data = json.load(scan_file)
except json.JSONDecodeError:
scan_file.seek(0)
data = []
buf = ""
for line in scan_file:
if not line.strip():
continue
buf += line.decode("utf-8") if isinstance(line, bytes) else line
try:
data.append(json.loads(buf))
buf = ""
except json.JSONDecodeError:
continue
if not data:
raise ValueError
except Exception:
msg = "Invalid JSON format"
raise ValueError(msg)
Expand Down Expand Up @@ -160,7 +176,7 @@ def get_findings(self, scan_file, test):
range_info = "\n ".join(formatted_ranges)

vuln_functions = ", ".join(
set(osv_data["affected"][0]["ecosystem_specific"]["imports"][0].get("symbols", [])),
set(osv_data["affected"][0].get("ecosystem_specific", {}).get("imports", [{}])[0].get("symbols", [])),
)

description = (
Expand All @@ -172,7 +188,7 @@ def get_findings(self, scan_file, test):
f"**Traces found :**\n{self.get_finding_trace_info(data, osv_data['id'])}"
)

references = [f"{ref['type']}: {ref['url']}" for ref in osv_data["references"]]
references = [f"{ref['type']}: {ref['url']}" for ref in osv_data.get("references", [])]
db_specific_url = osv_data["database_specific"].get("url", "Unknown")
if db_specific_url:
references.append(f"Database: {db_specific_url}")
Expand Down
Loading
Loading