@@ -64,7 +64,6 @@ def process_file(self, file):
6464 xml_root = ET .parse (file ).getroot ()
6565 id = xml_root .attrib .get ("id" )
6666 glsa = "GLSA-" + id
67-
6867 vuln_references = [
6968 ReferenceV2 (
7069 reference_id = glsa ,
@@ -82,7 +81,21 @@ def process_file(self, file):
8281 summary = child .text
8382
8483 if child .tag == "affected" :
85- affected_packages = list (affected_and_safe_purls (child ))
84+ affected_packages = []
85+ seen_packages = set ()
86+
87+ for purl , constraint in get_affected_and_safe_purls (child ):
88+ signature = (purl .to_string (), str (constraint ))
89+
90+ if signature not in seen_packages :
91+ seen_packages .add (signature )
92+
93+ affected_package = AffectedPackageV2 (
94+ package = purl ,
95+ affected_version_range = EbuildVersionRange (constraints = [constraint ]),
96+ fixed_version_range = None ,
97+ )
98+ affected_packages .append (affected_package )
8699
87100 if child .tag == "impact" :
88101 severity_value = child .attrib .get ("type" )
@@ -121,10 +134,7 @@ def cves_from_reference(reference):
121134 return cves
122135
123136
124- def _yield_packages (pkg_name , pkg_ns , constraints , invert ):
125- """
126- Generate AffectedPackageV2 objects for a list of constraints.
127- """
137+ def extract_purls_and_constraints (pkg_name , pkg_ns , constraints , invert ):
128138 for comparator , version , slot_value in constraints :
129139 qualifiers = {"slot" : slot_value } if slot_value else {}
130140 purl = PackageURL (type = "ebuild" , name = pkg_name , namespace = pkg_ns , qualifiers = qualifiers )
@@ -135,16 +145,12 @@ def _yield_packages(pkg_name, pkg_ns, constraints, invert):
135145 if invert :
136146 constraint = constraint .invert ()
137147
138- yield AffectedPackageV2 (
139- package = purl ,
140- affected_version_range = EbuildVersionRange (constraints = [constraint ]),
141- fixed_version_range = None ,
142- )
148+ yield purl , constraint
143149 except InvalidVersion as e :
144150 logger .error (f"InvalidVersion constraints version: { version } error:{ e } " )
145151
146152
147- def affected_and_safe_purls (affected_elem ):
153+ def get_affected_and_safe_purls (affected_elem ):
148154 for pkg in affected_elem :
149155 name = pkg .attrib .get ("name" )
150156 if not name :
@@ -153,8 +159,10 @@ def affected_and_safe_purls(affected_elem):
153159
154160 safe_constraints , affected_constraints = get_safe_and_affected_constraints (pkg )
155161
156- yield from _yield_packages (pkg_name , pkg_ns , affected_constraints , invert = False )
157- yield from _yield_packages (pkg_name , pkg_ns , safe_constraints , invert = True )
162+ yield from extract_purls_and_constraints (
163+ pkg_name , pkg_ns , affected_constraints , invert = False
164+ )
165+ yield from extract_purls_and_constraints (pkg_name , pkg_ns , safe_constraints , invert = True )
158166
159167
160168def get_safe_and_affected_constraints (pkg ):
0 commit comments