Skip to content

Commit d93a7c8

Browse files
Use patch classification utility for Tomcat commit collection
Signed-off-by: Dhirenderchoudhary <dhirenderchoudhary0001@gmail.com>
1 parent 5316e68 commit d93a7c8

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

vulnerabilities/pipelines/v2_importers/apache_tomcat_importer.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
from vulnerabilities.importer import AdvisoryDataV2
2828
from vulnerabilities.importer import AffectedPackageV2
29-
from vulnerabilities.importer import PackageCommitPatchData
3029
from vulnerabilities.importer import ReferenceV2
3130
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
31+
from vulnerabilities.pipes.advisory import append_patch_classifications
3232

3333
GITHUB_COMMIT_URL_RE = re.compile(
3434
r"https?://github\.com/apache/tomcat/commit/(?P<commit_hash>[0-9a-f]{5,40})"
@@ -293,8 +293,13 @@ def parse_tomcat_security(html_content):
293293
soup = BeautifulSoup(html_content, "lxml")
294294
results = []
295295

296-
for header in soup.find_all("h3", id=re.compile(r"Fixed_in_Apache_Tomcat")):
297-
m = re.search(r"Tomcat\s+([\d\.]+)", header.get_text())
296+
for header in soup.find_all("h3"):
297+
header_text = header.get_text(" ", strip=True)
298+
m = re.search(
299+
r"(?:Tomcat\s+|Fixed\s+(?:in\s+)?)((?:\d+\.)*\d+)",
300+
header_text,
301+
flags=re.IGNORECASE,
302+
)
298303
if not m:
299304
continue
300305
fixed_in = m.group(1)
@@ -327,7 +332,8 @@ def parse_tomcat_security(html_content):
327332
if current:
328333
text = p.get_text(" ", strip=True)
329334

330-
if "was fixed" in text.lower():
335+
lower_text = text.lower()
336+
if "fixed" in lower_text and "commit" in lower_text:
331337
for link in p.find_all("a", href=True):
332338
href = link["href"]
333339
if GITHUB_COMMIT_URL_RE.match(href) or GITBOX_COMMIT_URL_RE.match(href):
@@ -360,12 +366,20 @@ def get_commit_patches(commit_urls):
360366
commit_patches = []
361367
for url in commit_urls:
362368
match = GITHUB_COMMIT_URL_RE.match(url) or GITBOX_COMMIT_URL_RE.match(url)
363-
if match:
364-
commit_hash = match.group("commit_hash")
365-
commit_patches.append(
366-
PackageCommitPatchData(
367-
vcs_url=TOMCAT_VCS_URL,
368-
commit_hash=commit_hash,
369-
)
370-
)
369+
if not match:
370+
continue
371+
372+
commit_hash = match.group("commit_hash")
373+
classified_packages = []
374+
append_patch_classifications(
375+
url=url,
376+
commit_hash=commit_hash,
377+
patch_text=None,
378+
affected_packages=classified_packages,
379+
patches=[],
380+
references=[],
381+
)
382+
for package in classified_packages:
383+
for patch in package.fixed_by_commit_patches:
384+
commit_patches.append(patch)
371385
return commit_patches

0 commit comments

Comments
 (0)