Skip to content

Commit 79f6f71

Browse files
committed
Adjust the code according to changes in postgres html page
Fixed get_or_create_from_purl Signed-off-by: Tushar Goel <[email protected]>
1 parent 03d9309 commit 79f6f71

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

vulnerabilities/importers/postgresql.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def to_advisories(data):
9999
# in the prior code, this is the only place where cve_id was defined, and presumably
100100
# there was no error like the error we got:
101101
# UnboundLocalError: local variable 'cve_id' referenced before assignment
102-
cve_id = ref_col.select("nobr")[0].text
102+
103+
# changed from nobr to .nobr due to html changes
104+
cve_id = ref_col.select(".nobr")[0].text
103105
# This is for the anomaly in https://www.postgresql.org/support/security/8.1/ 's
104106
# last entry
105107
except IndexError:
@@ -142,7 +144,7 @@ def to_advisories(data):
142144

143145

144146
def find_advisory_urls(page_data):
145-
soup = BeautifulSoup(page_data)
147+
soup = BeautifulSoup(page_data, features="lxml")
146148
return {
147149
urlparse.urljoin("https://www.postgresql.org/", a_tag.attrs["href"])
148150
for a_tag in soup.select("h3+ p a")

vulnerabilities/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,20 @@ def get_or_create_from_purl(self, purl: PackageURL):
324324
``purl`` PackageURL.
325325
"""
326326
purl_fields = without_empty_values(purl.to_dict(encode=True))
327+
328+
# when there are 2 packages one with qualifiers and one without
329+
# qualifiers, having all other fields same, this raises MultipleObjectsReturned
330+
# so we are filling out the fields with empty value to avoid this
331+
for field in PackageURL._fields:
332+
# name, type, and version are required fields
333+
if field not in purl_fields:
334+
if field == "namespace":
335+
purl_fields[field] = ""
336+
if field == "qualifiers":
337+
purl_fields[field] = {}
338+
if field == "subpath":
339+
purl_fields[field] = ""
340+
327341
package, _ = Package.objects.get_or_create(**purl_fields)
328342
return package
329343

vulnerabilities/tests/test_data/postgresql/advisories.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ <h2>Known security issues in all supported versions</h2>
109109

110110
<tr>
111111
<td>
112-
<nobr><a href="/support/security/CVE-2020-10733/">CVE-2020-10733</a></nobr><br>
112+
<a href="/support/security/CVE-2020-10733/" class="nobr">CVE-2020-10733</a><br>
113113
<a href="/about/news/postgresql-123-118-1013-9618-and-9522-released-2038/">Announcement</a><br>
114114
</td>
115115
<td>12, 11, 10, 9.6</td>
@@ -122,7 +122,7 @@ <h2>Known security issues in all supported versions</h2>
122122

123123
<tr>
124124
<td>
125-
<nobr><a href="/support/security/CVE-2020-1720/">CVE-2020-1720</a></nobr><br>
125+
<a href="/support/security/CVE-2020-1720/" class="nobr">CVE-2020-1720</a><br>
126126
<a href="/about/news/postgresql-122-117-1012-9617-9521-and-9426-released-2011/">Announcement</a><br>
127127
</td>
128128
<td>12, 11, 10, 9.6</td>

0 commit comments

Comments
 (0)