From patchwork Thu Aug 4 16:47:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Roberts, William C" X-Patchwork-Id: 9263939 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 5227A60839 for ; Thu, 4 Aug 2016 16:55:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43F4828406 for ; Thu, 4 Aug 2016 16:55:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 386492841D; Thu, 4 Aug 2016 16:55:29 +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 61EFE28406 for ; Thu, 4 Aug 2016 16:55:27 +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 16:51:14 +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 u74GlMkL031230; Thu, 4 Aug 2016 12:48:25 -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 u74GlIuW249580 for ; Thu, 4 Aug 2016 12:47:18 -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 u74GlJCm031222; Thu, 4 Aug 2016 12:47:20 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CfBwBrcKNX/yNjr8ZdGwEBAYMngVKlEpF5hAwUhgmBSkwBAQEBAQFehS8ECwFGMAUCJgJgEogxrn+QDAEBAQEGAQEBASOBAYcphyqCZIJaBY8MiiiPAgKPPkiPYFSEGhwyAYdMAQEB X-IPAS-Result: A1CfBwBrcKNX/yNjr8ZdGwEBAYMngVKlEpF5hAwUhgmBSkwBAQEBAQFehS8ECwFGMAUCJgJgEogxrn+QDAEBAQEGAQEBASOBAYcphyqCZIJaBY8MiiiPAgKPPkiPYFSEGhwyAYdMAQEB X-IronPort-AV: E=Sophos;i="5.28,470,1464667200"; d="scan'208";a="5625983" 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 12:47:57 -0400 Received: from fmsmga002-icc.fm.intel.com ([198.175.99.35]) by emsm-gh1-uea11.nsa.gov with ESMTP; 04 Aug 2016 16:47:08 +0000 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,470,1464678000"; d="scan'208"; a="1035160015" Received: from hhariri-mobl2.amr.corp.intel.com (HELO wcrobert-MOBL1.amr.corp.intel.com) ([10.252.130.218]) by fmsmga002.fm.intel.com with ESMTP; 04 Aug 2016 09:47:07 -0700 From: william.c.roberts@intel.com To: selinux@tycho.nsa.gov, seandroid-list@tycho.nsa.gov, sds@tycho.nsa.gov Subject: [PATCH v3] module_to_cil: fix possible use of initialized value Date: Thu, 4 Aug 2016 09:47:04 -0700 Message-Id: <1470329224-17870-1-git-send-email-william.c.roberts@intel.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 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: Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP From: William Roberts Correct errors like these reported by gcc: module_to_cil.c: In function ‘block_to_cil’: module_to_cil.c:229:20: error: ‘attr_list’ may be used uninitialized in this function [-Werror=maybe-uninitialized] struct list_node *curr = (*attr_list)->head; Usages of attr_list_destroy() were called when list_init() fails. stack_init() and stack_destroy() also suffered from the aforementioned issue. To correct the issue, initialize stack and list variables to NULL. Signed-off-by: William Roberts --- libsepol/src/module_to_cil.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c index b9a4af7..c74f357 100644 --- a/libsepol/src/module_to_cil.c +++ b/libsepol/src/module_to_cil.c @@ -1303,11 +1303,11 @@ static int cond_list_to_cil(int indent, struct policydb *pdb, struct cond_node * { int rc = -1; struct cond_node *cond; - struct list *attr_list; + struct list *attr_list = NULL; rc = list_init(&attr_list); if (rc != 0) { - goto exit; + goto exit;; } for (cond = cond_list; cond != NULL; cond = cond->next) { @@ -3482,7 +3482,7 @@ static int block_to_cil(struct policydb *pdb, struct avrule_block *block, struct { int rc = -1; struct avrule_decl *decl; - struct list *attr_list; + struct list *attr_list = NULL; decl = block->branch_list; @@ -3631,7 +3631,7 @@ static int blocks_to_cil(struct policydb *pdb) int rc = -1; struct avrule_block *block; int indent = 0; - struct stack *stack; + struct stack *stack = NULL; rc = stack_init(&stack); if (rc != 0) { @@ -3699,7 +3699,7 @@ static int linked_blocks_to_cil(struct policydb *pdb) // Since it is linked, all optional blocks have been resolved int rc = -1; struct avrule_block *block; - struct stack *stack; + struct stack *stack = NULL; rc = stack_init(&stack); if (rc != 0) {