|
26 | 26 |
|
27 | 27 | from vulnerabilities.importer import AdvisoryDataV2 |
28 | 28 | from vulnerabilities.importer import AffectedPackageV2 |
29 | | -from vulnerabilities.importer import PackageCommitPatchData |
30 | 29 | from vulnerabilities.importer import ReferenceV2 |
31 | 30 | from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2 |
| 31 | +from vulnerabilities.pipes.advisory import append_patch_classifications |
32 | 32 |
|
33 | 33 | GITHUB_COMMIT_URL_RE = re.compile( |
34 | 34 | 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): |
293 | 293 | soup = BeautifulSoup(html_content, "lxml") |
294 | 294 | results = [] |
295 | 295 |
|
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 | + ) |
298 | 303 | if not m: |
299 | 304 | continue |
300 | 305 | fixed_in = m.group(1) |
@@ -327,7 +332,8 @@ def parse_tomcat_security(html_content): |
327 | 332 | if current: |
328 | 333 | text = p.get_text(" ", strip=True) |
329 | 334 |
|
330 | | - if "was fixed" in text.lower(): |
| 335 | + lower_text = text.lower() |
| 336 | + if "fixed" in lower_text and "commit" in lower_text: |
331 | 337 | for link in p.find_all("a", href=True): |
332 | 338 | href = link["href"] |
333 | 339 | if GITHUB_COMMIT_URL_RE.match(href) or GITBOX_COMMIT_URL_RE.match(href): |
@@ -360,12 +366,20 @@ def get_commit_patches(commit_urls): |
360 | 366 | commit_patches = [] |
361 | 367 | for url in commit_urls: |
362 | 368 | 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) |
371 | 385 | return commit_patches |
0 commit comments