From patchwork Wed Nov 4 14:51:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 1394039 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CR8lG30Znz9sTK for ; Thu, 5 Nov 2020 01:52:42 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 04095203F5; Wed, 4 Nov 2020 14:52:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pTRq6hWd6Ls9; Wed, 4 Nov 2020 14:52:33 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 7F1DD20443; Wed, 4 Nov 2020 14:52:18 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 03ED51BF2CE for ; Wed, 4 Nov 2020 14:52:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id F25B0866B6 for ; Wed, 4 Nov 2020 14:52:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X7O+Ze0BD6eP for ; Wed, 4 Nov 2020 14:52:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by whitealder.osuosl.org (Postfix) with ESMTPS id CB6AF866C3 for ; Wed, 4 Nov 2020 14:52:06 +0000 (UTC) X-Originating-IP: 86.201.80.25 Received: from localhost (lfbn-tou-1-236-25.w86-201.abo.wanadoo.fr [86.201.80.25]) (Authenticated sender: thomas.petazzoni@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 24B88240010; Wed, 4 Nov 2020 14:52:03 +0000 (UTC) From: Thomas Petazzoni To: Buildroot List Date: Wed, 4 Nov 2020 15:51:42 +0100 Message-Id: <20201104145145.1316167-9-thomas.petazzoni@bootlin.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201104145145.1316167-1-thomas.petazzoni@bootlin.com> References: <20201104145145.1316167-1-thomas.petazzoni@bootlin.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCH 08/10] support/script/pkg-stats: show CPE ID in results X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matt Weber , Thomas Petazzoni Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Gregory CLEMENT This commit improves the pkg-stats script to show the CPE ID of packages, if available. For now, it doesn't use CPE IDs to match CVEs. Signed-off-by: Gregory CLEMENT Signed-off-by: Thomas Petazzoni Reviewed-by: Matt Weber Tested-by: Heiko Thiery --- support/scripts/pkg-stats | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/support/scripts/pkg-stats b/support/scripts/pkg-stats index 503cc45c16..0a48cf9581 100755 --- a/support/scripts/pkg-stats +++ b/support/scripts/pkg-stats @@ -76,6 +76,7 @@ class Package: all_license_files = list() all_versions = dict() all_ignored_cves = dict() + all_cpeids = dict () # This is the list of all possible checks. Add new checks to this list so # a tool that post-processeds the json output knows the checks before # iterating over the packages. @@ -96,6 +97,7 @@ class Package: self.current_version = None self.url = None self.url_worker = None + self.cpeid = None self.cves = list() self.latest_version = {'status': RM_API_STATUS_ERROR, 'version': None, 'id': None} self.status = {} @@ -210,6 +212,14 @@ class Package: if var in self.all_versions: self.current_version = self.all_versions[var] + def set_cpeid(self): + """ + Fills in the .cpeid field + """ + var = self.pkgvar() + if var in self.all_cpeids: + self.cpeid = self.all_cpeids[var] + def set_check_package_warnings(self): """ Fills in the .warnings and .status['pkg-check'] fields @@ -333,7 +343,7 @@ def get_pkglist(npackages, package_list): def package_init_make_info(): # Fetch all variables at once variables = subprocess.check_output(["make", "BR2_HAVE_DOT_CONFIG=y", "-s", "printvars", - "VARS=%_LICENSE %_LICENSE_FILES %_VERSION %_IGNORE_CVES"]) + "VARS=%_LICENSE %_LICENSE_FILES %_VERSION %_IGNORE_CVES %_CPE_ID"]) variable_list = variables.decode().splitlines() # We process first the host package VERSION, and then the target @@ -371,6 +381,9 @@ def package_init_make_info(): pkgvar = pkgvar[:-12] Package.all_ignored_cves[pkgvar] = value.split() + elif pkgvar.endswith("_CPE_ID"): + pkgvar = pkgvar[:-7] + Package.all_cpeids[pkgvar] = value check_url_count = 0 @@ -578,6 +591,10 @@ def calculate_stats(packages): stats["total-cves"] += len(pkg.cves) if len(pkg.cves) != 0: stats["pkg-cves"] += 1 + if pkg.cpeid: + stats["cpe-id"] += 1 + else: + stats["no-cpe-id"] += 1 return stats @@ -800,6 +817,19 @@ def dump_html_pkg(f, pkg): f.write(" %s
\n" % (cve, cve)) f.write(" \n") + # CPE ID + td_class = ["left"] + if pkg.cpeid: + td_class.append("correct") + else: + td_class.append("wrong") + f.write(" \n" % " ".join(td_class)) + if pkg.cpeid: + f.write(" %s\n" % pkg.cpeid) + else: + f.write(" N/A\n") + f.write(" \n") + f.write(" \n") @@ -818,6 +848,7 @@ def dump_html_all_pkgs(f, packages): Warnings Upstream URL CVEs +CPE ID """) for pkg in sorted(packages): @@ -860,6 +891,10 @@ def dump_html_stats(f, stats): stats["pkg-cves"]) f.write("Total number of CVEs affecting all packages%s\n" % stats["total-cves"]) + f.write("Packages with CPE ID%s\n" % + stats["cpe-id"]) + f.write("Packages without CPE ID%s\n" % + stats["no-cpe-id"]) f.write("\n") @@ -932,11 +967,17 @@ def parse_args(): help='List of packages (comma separated)') parser.add_argument('--nvd-path', dest='nvd_path', help='Path to the local NVD database', type=resolvepath) + parser.add_argument("--cpeid", action='store_true') args = parser.parse_args() if not args.html and not args.json: parser.error('at least one of --html or --json (or both) is required') return args +def cpeid_name(pkg): + try: + return pkg.cpeid.split(':')[1] + except: + return '' def __main__(): args = parse_args() @@ -965,6 +1006,7 @@ def __main__(): pkg.set_patch_count() pkg.set_check_package_warnings() pkg.set_current_version() + pkg.set_cpeid() pkg.set_url() pkg.set_developers(developers) print("Checking URL status")