Merge ~alexmurray/ubuntu-cve-tracker:optimise-cve-lib-get-long-kernel-hash into ubuntu-cve-tracker:master

Proposed by Alex Murray
Status: Merged
Merged at revision: f77960c691522ef8d1c638bd26f56a5c056cd243
Proposed branch: ~alexmurray/ubuntu-cve-tracker:optimise-cve-lib-get-long-kernel-hash
Merge into: ubuntu-cve-tracker:master
Diff against target: 30 lines (+15/-1)
1 file modified
scripts/cve_lib.py (+15/-1)
Reviewer Review Type Date Requested Status
Seth Arnold Approve
Marc Deslauriers Approve
Review via email: mp+462745@code.launchpad.net

Description of the change

scripts/cve_lib.py: optimise get_long_kernel_hash()

The initial kernel git commit is a single huge commit which added the entire
2.6.12-rc2 kernel into the git repo - as such, fetching this takes a really long
time AND it is both a common Fixes: commit since it is used for anything which
has existed in the kernel since that time. So optimise for this case by checking
specifically if a short_hash matches this and just returning the known full
commit hash in that case without looking it up. Also for the general case, since
we really only need the first line of the commit patch body to get the "From "
line, just fetch the first 1k of the patch without waiting for the rest.

Signed-off-by: Alex Murray <email address hidden>

To post a comment you must log in.
Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

LGTM, thanks!

review: Approve
Revision history for this message
Seth Arnold (seth-arnold) wrote :

I like it; 12 chars might be too long for it to ever actually work in practice, but it's a very safe length :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/scripts/cve_lib.py b/scripts/cve_lib.py
index d8e274d..95c8f65 100755
--- a/scripts/cve_lib.py
+++ b/scripts/cve_lib.py
@@ -3571,10 +3571,24 @@ def in_break_fixes(commit, break_fixes):
35713571
3572def get_long_kernel_hash(short_hash):3572def get_long_kernel_hash(short_hash):
3573 '''Attempts to get a long kernel hash'''3573 '''Attempts to get a long kernel hash'''
3574 # don't try and fetch the initial kernel git commit as this is huge
3575 INITIAL_COMMIT_HASH="1da177e4c3f41524e886b7f1b8a0c1fc7321cac2"
3576 # but we also don't want to match on a short_hash like '1' either so if we
3577 # are going to use this short-cut ensure we have enough of a short_hash that
3578 # it is likely unique
3579 # [ $(git rev-parse --short $INITIAL_COMMIT_HASH | wc -c) -eq 13 ]
3580 if len(short_hash) > 12 and INITIAL_COMMIT_HASH.startswith(short_hash):
3581 return INITIAL_COMMIT_HASH
35743582
3575 url = 'https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/patch/?id=' + short_hash3583 url = 'https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/patch/?id=' + short_hash
3576 with urllib.request.urlopen(url) as response:3584 with urllib.request.urlopen(url) as response:
3577 patch = response.read().decode('utf-8')3585 try:
3586 # we only need the first line of the patch so limit to the first
3587 # 1024 bytes
3588 patch = response.read(1024).decode('utf-8')
3589 except Exception as e:
3590 print("Failed to fetch patch via url '%s': %s" % (url, str(e)), file=sys.stderr)
3591 return short_hash
35783592
3579 for line in patch.split("\n"):3593 for line in patch.split("\n"):
3580 if line.startswith("From "):3594 if line.startswith("From "):

Subscribers

People subscribed via source and target branches