test_patch_cve.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Checks related to the patch's CVE lines
  2. #
  3. # Copyright (C) 2016 Intel Corporation
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-only
  6. #
  7. import base
  8. import os
  9. import pyparsing
  10. class CVE(base.Base):
  11. re_cve_pattern = pyparsing.Regex("CVE\-\d{4}\-\d+")
  12. re_cve_payload_tag = pyparsing.Regex("\+CVE:(\s+CVE\-\d{4}\-\d+)+")
  13. def setUp(self):
  14. if self.unidiff_parse_error:
  15. self.skip('Parse error %s' % self.unidiff_parse_error)
  16. # we are just interested in series that introduce CVE patches, thus discard other
  17. # possibilities: modification to current CVEs, patch directly introduced into the
  18. # recipe, upgrades already including the CVE, etc.
  19. new_cves = [p for p in self.patchset if p.path.endswith('.patch') and p.is_added_file]
  20. if not new_cves:
  21. self.skip('No new CVE patches introduced')
  22. def test_cve_tag_format(self):
  23. for commit in CVE.commits:
  24. if self.re_cve_pattern.search_string(commit.shortlog) or self.re_cve_pattern.search_string(commit.commit_message):
  25. tag_found = False
  26. for line in commit.payload.splitlines():
  27. if self.re_cve_payload_tag.search_string(line):
  28. tag_found = True
  29. break
  30. if not tag_found:
  31. self.fail('Missing or incorrectly formatted CVE tag in patch file. Correct or include the CVE tag in the patch with format: "CVE: CVE-YYYY-XXXX"',
  32. commit=commit)