Skip to content

Commit e057631

Browse files
Fixed issue downloading XML reports
The XML report has an extra </report> tag which prevents the .text method from working properly. I used the .to_s method instead. I also moved the rescue statement because it was masking other errors that were being raised.
1 parent cb33c56 commit e057631

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

lib/openvas/openvas-omp.rb

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -604,33 +604,36 @@ def report_get_by_id(report_id, format_id)
604604
if not report
605605
raise OMPError.new("Invalid report id.")
606606
end
607+
607608
format = @formats[format_id.to_i]
608609
if not format
609610
raise OMPError.new("Invalid format id.")
610611
end
611-
req = xml_attrs("get_reports", {"report_id"=>report["id"], "format_id"=>format["id"]})
612612

613+
req = xml_attrs("get_reports", {"report_id"=>report["id"], "format_id"=>format["id"]})
613614
begin
614615
status, status_text, resp = omp_request_xml(req)
615-
if status == "404"
616-
raise OMPError.new(status_text)
617-
end
618-
content_type = resp.elements["report"].attributes["content_type"]
619-
report = resp.elements["report"].text
620-
621-
if report == nil
622-
raise OMPError.new("The report is empty.")
623-
end
624-
625-
# XML reports are in XML format, everything else is base64 encoded.
626-
if content_type == "text/xml"
627-
return resp.elements["report"].text
628-
else
629-
return Base64.decode64(resp.elements["report"].text)
630-
end
631616
rescue
632617
raise OMPResponseError
633618
end
619+
620+
if status == "404"
621+
raise OMPError.new(status_text)
622+
end
623+
624+
content_type = resp.elements["report"].attributes["content_type"]
625+
report = resp.elements["report"].to_s
626+
627+
if report == nil
628+
raise OMPError.new("The report is empty.")
629+
end
630+
631+
# XML reports are in XML format, everything else is base64 encoded.
632+
if content_type == "text/xml"
633+
return report
634+
else
635+
return Base64.decode64(report)
636+
end
634637
end
635638

636639
end

0 commit comments

Comments
 (0)