From 67f420c0f0a1fc0bb456dd48181ca3c16da6b48e Mon Sep 17 00:00:00 2001 From: savish Date: Thu, 18 Mar 2021 20:13:29 +0530 Subject: [PATCH] Sanity Checks for redhat import response Signed-off-by: savish --- vulnerabilities/importers/redhat.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/vulnerabilities/importers/redhat.py b/vulnerabilities/importers/redhat.py index 1fba1c484..08e49c5ef 100644 --- a/vulnerabilities/importers/redhat.py +++ b/vulnerabilities/importers/redhat.py @@ -91,19 +91,24 @@ def to_advisory(advisory_data): if bugzilla: url = "https://bugzilla.redhat.com/show_bug.cgi?id={}".format(bugzilla) bugzilla_data = requests.get(f"https://bugzilla.redhat.com/rest/bug/{bugzilla}").json() - bugzilla_severity_val = bugzilla_data["bugs"][0]["severity"] - bugzilla_severity = VulnerabilitySeverity( - system=scoring_systems["rhbs"], - value=bugzilla_severity_val, - ) + if ( + ("bugs" in bugzilla_data) + and len(bugzilla_data["bugs"]) + and ("severity" in bugzilla_data["bugs"][0]) + ): + bugzilla_severity_val = bugzilla_data["bugs"][0]["severity"] + bugzilla_severity = VulnerabilitySeverity( + system=scoring_systems["rhbs"], + value=bugzilla_severity_val, + ) - references.append( - Reference( - severities=[bugzilla_severity], - url=url, - reference_id=bugzilla, + references.append( + Reference( + severities=[bugzilla_severity], + url=url, + reference_id=bugzilla, + ) ) - ) for rh_adv in advisory_data["advisories"]: # RH provides 3 types of advisories RHSA, RHBA, RHEA. Only RHSA's contain severity score.