-
Notifications
You must be signed in to change notification settings - Fork 1
[CKC] Add CVE verification with --check-cves option #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |||||
| import re | ||||||
| import sys | ||||||
| import textwrap | ||||||
| import os | ||||||
| from typing import Optional | ||||||
|
|
||||||
| def run_git(repo, args): | ||||||
| """Run a git command in the given repository and return its output as a string.""" | ||||||
|
|
@@ -50,14 +52,15 @@ def find_fixes_in_mainline(repo, pr_branch, upstream_ref, hash_): | |||||
| """ | ||||||
| Return unique commits in upstream_ref that have Fixes: <N chars of hash_> in their message, case-insensitive. | ||||||
| Start from 12 chars and work down to 6, but do not include duplicates if already found at a longer length. | ||||||
| Returns a list of tuples: (full_hash, display_string) | ||||||
| """ | ||||||
| results = [] | ||||||
| # Get all commits with 'Fixes:' in the message | ||||||
| output = run_git(repo, [ | ||||||
| 'log', upstream_ref, '--grep', 'Fixes:', '-i', '--format=%H %h %s (%an)%x0a%B%x00' | ||||||
| ]).strip() | ||||||
| if not output: | ||||||
| return "" | ||||||
| return [] | ||||||
| # Each commit is separated by a NUL character and a newline | ||||||
| commits = output.split('\x00\x0a') | ||||||
| # Prepare hash prefixes from 12 down to 6 | ||||||
|
|
@@ -78,11 +81,11 @@ def find_fixes_in_mainline(repo, pr_branch, upstream_ref, hash_): | |||||
| for prefix in hash_prefixes: | ||||||
| if m.group(1).lower().startswith(prefix.lower()): | ||||||
| if not commit_exists_in_branch(repo, pr_branch, full_hash): | ||||||
| results.append(' '.join(header.split()[1:])) | ||||||
| results.append((full_hash, ' '.join(header.split()[1:]))) | ||||||
| break | ||||||
| else: | ||||||
| continue | ||||||
| return "\n".join(results) | ||||||
| return results | ||||||
|
|
||||||
| def commit_exists_in_branch(repo, pr_branch, upstream_hash_): | ||||||
| """ | ||||||
|
|
@@ -104,17 +107,75 @@ def wrap_paragraph(text, width=80, initial_indent='', subsequent_indent=''): | |||||
| break_on_hyphens=False) | ||||||
| return wrapper.fill(text) | ||||||
|
|
||||||
| def extract_cve_from_message(msg): | ||||||
| """Extract CVE reference from commit message. Returns CVE ID or None. | ||||||
| Only matches 'cve CVE-2025-12345', ignores 'cve-bf' and 'cve-pre' variants.""" | ||||||
| match = re.search(r'(?<!\S)cve\s+(CVE-\d{4}-\d+)', msg, re.IGNORECASE) | ||||||
bmastbergen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| match = re.search(r'(?<!\S)cve\s+(CVE-\d{4}-\d+)', msg, re.IGNORECASE) | |
| match = re.search(r'\bcve\s+(CVE-\d{4}-\d+)', msg, re.IGNORECASE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh Co-Pilot, your contexted didn't even follow the comment directly above which you also whined about.
roxanan1996 marked this conversation as resolved.
Show resolved
Hide resolved
roxanan1996 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really hate this tree of if statements.
Can we make a ticket to clean this up ... ideally as a part of python mock testing ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PlaidCat Yees, I fully agree with you! On my list to refactor this when I migrate to 'kt'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The docstring example uses CVE-2025-12345 which appears to be a future year. Consider using a more realistic example like CVE-2024-12345 or CVE-2023-12345.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The future is now copilot! Its 2025!