From b73f07b9fb80c297d74a6cb793ad881e7e9303e3 Mon Sep 17 00:00:00 2001
From: Nadin El-Yabroudi <nelyabroudi@cloudflare.com>
Date: Tue, 10 Mar 2020 10:15:09 -0700
Subject: [PATCH] Fix xml parser when host is up but not ports are open (#46).
 Also fix error when getting description from the cache. The entire vuln
 description object should be saved in the cache not just the string of the
 description. Also added all __pycache__ files to gitignore

---
 .gitignore                         | 1 +
 contrib/descriptions/cveproject.py | 5 +++--
 contrib/parsers/flan_xml_parser.py | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)
 create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bee8a64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+__pycache__
diff --git a/contrib/descriptions/cveproject.py b/contrib/descriptions/cveproject.py
index c6ad248..4b816c9 100644
--- a/contrib/descriptions/cveproject.py
+++ b/contrib/descriptions/cveproject.py
@@ -29,8 +29,9 @@ class CveProjectProvider(VulnDescriptionProvider):
                 response.raise_for_status()
                 cve_json = response.json()
                 description = cve_json['description']['description_data'][0]['value']
-                self.cache[vuln] = description
-                return VulnDescription(description, self.nist_uri_template.format(vuln))
+                vuln_description = VulnDescription(description, self.nist_uri_template.format(vuln))
+                self.cache[vuln] = vuln_description
+                return vuln_description
         except HTTPError as he:
             return VulnDescription('', 'Description fetching error: ' + str(he))
 
diff --git a/contrib/parsers/flan_xml_parser.py b/contrib/parsers/flan_xml_parser.py
index 7d88919..5254921 100644
--- a/contrib/parsers/flan_xml_parser.py
+++ b/contrib/parsers/flan_xml_parser.py
@@ -113,7 +113,7 @@ class FlanXmlParser:
         if not ip_addr:
             return
 
-        if host['status']['@state'] == 'up' and 'port' in host['ports']:
+        if host['status']['@state'] == 'up' and 'ports' in host.keys() and 'port' in host['ports']:
             ports = host['ports']['port']
             if isinstance(ports, list):
                 for p in ports:
-- 
GitLab