From aad8eb1c15a550241f3353fe87f3e9d3a0552c8f Mon Sep 17 00:00:00 2001 From: Michal Hocko Date: Mar 27 2024 08:34:29 +0000 Subject: Merge remote-tracking branch 'origin/users/mkoutny/scripts/cve-scripts' into users/mhocko/scripts/cve-scripts --- diff --git a/scripts/check-kernel-fix b/scripts/check-kernel-fix index f1bc2f6..4f752df 100755 --- a/scripts/check-kernel-fix +++ b/scripts/check-kernel-fix @@ -178,7 +178,8 @@ print_action() missing_references) patch=$(grep "^$branch:" "$patch_file" | cut -d : -f 2) if [ -n "$patch" ] ; then - action="$branch: RUN: add-missing-reference $patch $references" + ref_args=$(printf -- '-r %s ' $references) + action="$branch: RUN: scripts/cve_tools/add-missing-reference $ref_args$patch" else action="$branch: MANUAL: no patch has the references: $references" fi diff --git a/scripts/cve_tools/add-missing-reference b/scripts/cve_tools/add-missing-reference new file mode 100755 index 0000000..72af708 --- /dev/null +++ b/scripts/cve_tools/add-missing-reference @@ -0,0 +1,31 @@ +#!/usr/bin/python3 + +import argparse +import sys +import os.path + +scriptsdir = os.path.dirname(__file__) +sys.path.append(os.path.join(scriptsdir, "../git_sort")) +from patch import Patch + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Add references to patch file") + parser.add_argument("-r", "--reference", action="append", + help="bsc# or CVE token used to tag the patch file. The option can be used more times.") + parser.add_argument("patches", help="Patch files.", + nargs=argparse.REMAINDER) + args = parser.parse_args() + + + added_refs = list(args.reference) + for f in args.patches: + with Patch(open(f, "r+b")) as patch: + refs = "".join(patch.get("References")) + refs = list(refs.replace(",", " ").split()) + new_refs = refs + [r for r in added_refs if not r in refs] + if new_refs == refs: + continue + patch.change("References", " ".join(new_refs)) + +