From patchwork Thu Aug 4 12:50:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vit Mojzis X-Patchwork-Id: 9263581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0A58F6048F for ; Thu, 4 Aug 2016 12:53:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECEF7283E1 for ; Thu, 4 Aug 2016 12:53:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDCBC28406; Thu, 4 Aug 2016 12:53:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (smtp.nsa.gov [8.44.101.8]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 166B8283E1 for ; Thu, 4 Aug 2016 12:53:52 +0000 (UTC) Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 04 Aug 2016 12:51:57 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u74CpQfD004561; Thu, 4 Aug 2016 08:51:34 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u74CpN7W248701 for ; Thu, 4 Aug 2016 08:51:24 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u74CpPIe004559 for ; Thu, 4 Aug 2016 08:51:25 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DKAACtOaNXhxy3hNFdhBt8pXaCAgGMaoIphAwUEIV5gVRMAQEBAQEBEwEBAQoLCQkZhg2BUYgxDr5bATCGKolZhQ8FiB6HLYlphhqIaAKCN40FAkiPYIIVYoFZOjIBh0wBAQE X-IPAS-Result: A1DKAACtOaNXhxy3hNFdhBt8pXaCAgGMaoIphAwUEIV5gVRMAQEBAQEBEwEBAQoLCQkZhg2BUYgxDr5bATCGKolZhQ8FiB6HLYlphhqIaAKCN40FAkiPYIIVYoFZOjIBh0wBAQE X-IronPort-AV: E=Sophos;i="5.28,470,1464667200"; d="scan'208";a="5624361" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 04 Aug 2016 08:52:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Aug 2016 12:51:04 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66D433B709 for ; Thu, 4 Aug 2016 12:51:03 +0000 (UTC) Received: from localhost.localdomain.com ([10.40.3.26]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u74Cp2TR027191; Thu, 4 Aug 2016 08:51:02 -0400 From: Vit Mojzis To: selinux@tycho.nsa.gov Subject: [PATCH] policycoreutils/sepolicy: Check get_rpm_nvr_list() return value Date: Thu, 4 Aug 2016 14:50:53 +0200 Message-Id: <1470315053-18483-1-git-send-email-vmojzis@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 04 Aug 2016 12:51:03 +0000 (UTC) X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP get_rpm_nvr_list can fail to get the version of selinux-policy rpm package, which leads to error during spec file creation (attempt to invoke __getitem__ of "None" object). This patch sets the policy number to "0.0.0" in case rpm failed to get it. This change should be safe because it affects only an example of spec file. Variable "POLICYCOREUTILSVER" was removed (unused). fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1321499 Failed to retrieve rpm info for selinux-policy Traceback (most recent call last): File "/bin/selinux-polgengui", line 360, in forward self.generate_policy() File "/bin/selinux-polgengui", line 506, in generate_policy self.info(my_policy.generate(outputdir)) File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1382, in generate out += "%s # %s\n" % (self.write_spec(out_dir), _("Spec file")) File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1228, in write_spec fd.write(self.generate_spec()) File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1190, in generate_spec selinux_policyver = get_rpm_nvr_list("selinux-policy")[1] TypeError: 'NoneType' object has no attribute '__getitem__' Signed-off-by: Vit Mojzis --- policycoreutils/sepolicy/sepolicy/generate.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/policycoreutils/sepolicy/sepolicy/generate.py b/policycoreutils/sepolicy/sepolicy/generate.py index a92783a..1c67d99 100644 --- a/policycoreutils/sepolicy/sepolicy/generate.py +++ b/policycoreutils/sepolicy/sepolicy/generate.py @@ -1184,8 +1184,12 @@ allow %s_t %s_t:%s_socket name_%s; def generate_spec(self): newspec = "" - selinux_policyver = get_rpm_nvr_list("selinux-policy")[1] - POLICYCOREUTILSVER = get_rpm_nvr_list("checkpolicy")[1] + selinux_policynvr = get_rpm_nvr_list("selinux-policy") + + if selinux_policynvr is None: + selinux_policyver = "0.0.0" + else: + selinux_policyver = selinux_policynvr[1] newspec += spec.header_comment_section if self.type in APPLICATIONS: