Skip to content

Commit dbe2cbf

Browse files
committed
add more generic approach to handling redhat references
1 parent 9207999 commit dbe2cbf

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

security/utils.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from urllib.parse import urlparse
1818

1919
from security.models import CVE, CWE, Reference
20+
from util.logging import warning_message
2021

2122

2223
def get_cve_reference(cve_id):
@@ -111,22 +112,32 @@ def fixup_reference(ref):
111112
url = fixup_bugzilla_url(url)
112113
url = fixup_rhn_url(url)
113114
if url.hostname == 'access.redhat.com':
114-
if 'l1d-cache-eviction-and-vector-register-sampling' in url.path or \
115-
'security/vulnerabilities/speculativeexecution' in url.path or \
116-
'security/vulnerabilities/stackguard' in url.path:
117-
ref_type = 'Link'
118-
elif 'security/cve' in url.path:
115+
processed = False
116+
old_ref = url.path.split('/')[-1]
117+
if 'security/cve' in url.path:
119118
return
120-
else:
121-
old_ref = url.path.split('/')[-1]
119+
elif url.path.startswith('/solutions/') or url.path.startswith('/articles/'):
120+
ref_type = 'Link'
121+
processed = True
122+
elif url.path.startswith('/security/vulnerabilities/'):
123+
if old_ref.isdigit() or old_ref.isalpha():
124+
ref_type = 'Link'
125+
processed = True
126+
elif old_ref.startswith('cve'):
127+
ref_type = 'Link'
128+
processed = True
129+
if not processed:
122130
refs = old_ref.split('-')
123131
if ':' not in url.path:
124132
try:
125-
new_ref = f'{refs[0]}-{refs[1]}:{refs[2]}'
133+
if refs[0].upper() == 'RHSB':
134+
new_ref = f'{refs[0]}-{refs[1]}-{refs[2]}'
135+
else:
136+
new_ref = f'{refs[0]}-{refs[1]}:{refs[2]}'
126137
path = url.path.replace(old_ref, new_ref)
127138
url = url._replace(path=path)
128139
except IndexError:
129-
pass
140+
warning_message(f'Unable to process reference URL: {url}')
130141
ref_type = refs[0].upper()
131142
final_url = url.geturl()
132143
if final_url in ['https://launchpad.net/bugs/', 'https://launchpad.net/bugs/XXXXXX']:

0 commit comments

Comments
 (0)