MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / GentooImporter

Class GentooImporter

vulnerabilities/importers/gentoo.py:29–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28
29class GentooImporter(Importer):
30 repo_url = "git+https://anongit.gentoo.org/git/data/glsa.git"
31 spdx_license_expression = "CC-BY-SA-4.0"
32 # the license notice is at this url https://anongit.gentoo.org/ says:
33 # The contents of this document, unless otherwise expressly stated, are licensed
34 # under the [CC-BY-SA-4.0](https://creativecommons.org/licenses/by-sa/4.0/) license.
35 license_url = "https://creativecommons.org/licenses/by-sa/4.0/"
36 importer_name = "Gentoo Importer"
37
38 def advisory_data(self) -> Iterable[AdvisoryData]:
39 try:
40 self.clone(repo_url=self.repo_url)
41 base_path = Path(self.vcs_response.dest_dir)
42 for file_path in base_path.glob("**/*.xml"):
43 yield from self.process_file(file_path)
44 finally:
45 if self.vcs_response:
46 self.vcs_response.delete()
47
48 def process_file(self, file):
49 cves = []
50 summary = ""
51 vuln_references = []
52 xml_root = ET.parse(file).getroot()
53 id = xml_root.attrib.get("id")
54 if id:
55 glsa = "GLSA-" + id
56 vuln_references = [
57 Reference(
58 reference_id=glsa,
59 url=f"https://security.gentoo.org/glsa/{id}",
60 )
61 ]
62
63 for child in xml_root:
64 if child.tag == "references":
65 cves = self.cves_from_reference(child)
66
67 if child.tag == "synopsis":
68 summary = child.text
69
70 if child.tag == "affected":
71 affected_packages = list(self.affected_and_safe_purls(child))
72
73 # It is very inefficient, to create new Advisory for each CVE
74 # this way, but there seems no alternative.
75 for cve in cves:
76 yield AdvisoryData(
77 aliases=[cve],
78 summary=summary,
79 references=vuln_references,
80 affected_packages=affected_packages,
81 url=(
82 f"https://security.gentoo.org/glsa/{id}"
83 if id
84 else "https://security.gentoo.org/glsa"
85 ),
86 )

Callers 1

test_gentoo_importFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_gentoo_importFunction · 0.72