Skip to content

Commit de44674

Browse files
committed
Explore OvalParser() parsing process #1079
Reference: #1079 Signed-off-by: John M. Horan <johnmhoran@gmail.com>
1 parent ba8834c commit de44674

6 files changed

Lines changed: 174 additions & 205 deletions

File tree

vulnerabilities/importer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ def get_data_from_xml_doc(
458458
]
459459
affected_packages = []
460460
for test_data in definition_data["test_data"]:
461+
print("\ntest_data = {}\n".format(test_data["package_list"]))
461462
for package_name in test_data["package_list"]:
462463
affected_version_range = test_data["version_ranges"]
463464
vrc = RANGE_CLASS_BY_SCHEMES[pkg_metadata["type"]]
@@ -477,13 +478,14 @@ def get_data_from_xml_doc(
477478
affected_version_range=affected_version_range,
478479
)
479480
)
481+
print("affected_packages = {}".format(affected_packages))
480482
date_published = dateparser.parse(timestamp)
481483
if not date_published.tzinfo:
482484
date_published = date_published.replace(tzinfo=pytz.UTC)
483485
yield AdvisoryData(
484486
aliases=[vuln_id],
485487
summary=description,
486-
affected_packages=affected_packages,
488+
affected_packages=sorted(affected_packages),
487489
references=sorted(references),
488490
date_published=date_published,
489491
)

vulnerabilities/importers/suse_oval.py

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,20 @@ def __init__(self, *args, **kwargs):
2828
self.translations = {"less than": "<", "equals": "=", "greater than or equal": ">="}
2929

3030
def _fetch(self):
31-
# base_url = "https://ftp.suse.com/pub/projects/security/oval/"
3231
page = requests.get(self.base_url).text
3332
soup = BeautifulSoup(page, "lxml")
3433

35-
# print(
36-
# [
37-
# self.base_url + node.get("href")
38-
# for node in soup.find_all("a")
39-
# if node.get("href").endswith(".gz")
40-
# ]
41-
# )
42-
4334
suse_oval_files = [
4435
self.base_url + node.get("href")
4536
for node in soup.find_all("a")
4637
if node.get("href").endswith(".gz")
4738
]
4839

49-
# for testfile in suse_oval_files:
50-
# print(testfile)
51-
52-
# Temporary test of .gz version of one of the .xml files we test in test_suse_oval.py:
53-
# suse_oval_files = [
54-
# "https://ftp.suse.com/pub/projects/security/oval/opensuse.leap.micro.5.3.xml.gz"
55-
# ]
56-
57-
# TODO: 2023-01-18 Wednesday 18:49:06. For some reason, if I un-comment the code below, my print above stops working. Why?
58-
59-
# for suse_file in suse_oval_files:
60-
# # print("suse_file = {}".format(suse_file))
61-
# # Do we want to log as ubuntu.py does? If so, why does debian_oval.py not log?
62-
# response = requests.get(suse_file)
63-
# # print("\nresponse = {}\n".format(response))
40+
for suse_file in suse_oval_files:
41+
response = requests.get(suse_file)
6442

65-
# extracted = gzip.decompress(response.content)
66-
# # print("\nextracted = {}\n".format(extracted))
67-
# yield (
68-
# {"type": "rpm", "namespace": "opensuse"},
69-
# ET.ElementTree(ET.fromstring(extracted.decode("utf-8"))),
70-
# )
43+
extracted = gzip.decompress(response.content)
44+
yield (
45+
{"type": "rpm", "namespace": "opensuse"},
46+
ET.ElementTree(ET.fromstring(extracted.decode("utf-8"))),
47+
)

vulnerabilities/oval_parser.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ def get_data(self) -> List[Dict]:
3636
Return a list of OvalDefinition mappings.
3737
"""
3838
oval_data = []
39+
# print(len(self.all_definitions))
40+
print("\nlen(self.all_definitions) = {}\n".format(len(self.all_definitions)))
3941
for definition in self.all_definitions:
42+
# print(definition)
43+
# print(list(definition))
4044

4145
matching_tests = self.get_tests_of_definition(definition)
4246
if not matching_tests:
@@ -49,13 +53,15 @@ def get_data(self) -> List[Dict]:
4953
definition_data["reference_urls"] = self.get_urls_from_definition(definition)
5054

5155
definition_data["severity"] = self.get_severity_from_definition(definition)
52-
56+
print("\nlen(matching_tests) = {}\n".format(len(matching_tests)))
5357
for test in matching_tests:
5458
test_obj, test_state = self.get_object_state_of_test(test)
5559
if not test_obj or not test_state:
5660
continue
5761
test_data = {"package_list": []}
62+
print(test_obj)
5863
test_data["package_list"].extend(self.get_pkgs_from_obj(test_obj))
64+
print(self.get_pkgs_from_obj(test_obj))
5965
version_ranges = self.get_version_range_from_state(test_state)
6066
test_data["version_ranges"] = version_ranges
6167
definition_data["test_data"].append(test_data)
@@ -88,8 +94,9 @@ def get_tests_of_definition(self, definition: OvalDefinition) -> List[OvalTest]:
8894
break
8995
if valid_test:
9096
matching_tests.append(self.oval_document.getElementByID(ref))
97+
print(matching_tests)
9198

92-
return matching_tests
99+
return list(set(matching_tests))
93100

94101
def get_object_state_of_test(self, test: OvalTest) -> Tuple[OvalObject, OvalState]:
95102
"""

vulnerabilities/tests/test_data/suse_oval/suse-oval-CVE-2008-5679-expected.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55
],
66
"summary": "\n\tThe HTML parsing engine in Opera before 9.63 allows remote attackers to execute arbitrary code via crafted web pages that trigger an invalid pointer calculation and heap corruption.\n\t",
77
"affected_packages": [
8-
{
9-
"package": {
10-
"type": "rpm",
11-
"namespace": "opensuse",
12-
"name": "opera",
13-
"version": null,
14-
"qualifiers": null,
15-
"subpath": null
16-
},
17-
"affected_version_range": "vers:rpm/<9.63-1.1",
18-
"fixed_version": null
19-
},
208
{
219
"package": {
2210
"type": "rpm",

0 commit comments

Comments
 (0)