From patchwork Sat May 18 16:57:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Sm9ra2UgSMOkbcOkbMOkaW5lbg==?= X-Patchwork-Id: 10948983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA46376 for ; Sat, 18 May 2019 16:57:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C6C328518 for ; Sat, 18 May 2019 16:57:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D84028562; Sat, 18 May 2019 16:57:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD16728518 for ; Sat, 18 May 2019 16:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728783AbfERQ5I (ORCPT ); Sat, 18 May 2019 12:57:08 -0400 Received: from 48.23.240.77.static.louhi.net ([77.240.23.48]:37096 "EHLO kolttonen.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbfERQ5I (ORCPT ); Sat, 18 May 2019 12:57:08 -0400 Received: from 34-41-5D-CA-59-C7 (176-93-196-243.bb.dnainternet.fi [176.93.196.243]) (authenticated bits=0) by vcust561.louhi.net (8.14.7/8.14.7/0) with ESMTP id x4IGuoR6008607 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Sat, 18 May 2019 19:56:50 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 vcust561.louhi.net x4IGuoR6008607 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolttonen.fi; s=mail; t=1558198611; bh=vpnh3THTO15/+oODvCd8xHOl0IwW3kxamlVp6AKJQsw=; h=Date:From:To:Subject:From; b=fDWms0B+3hgCZt8bYUe3rTt8Zjir8ZL7wuETImnFYprKUPyrJ+VEpeO0tIankas7e PYNOXf22baC3jHkmz/8y/fZ6U/7CUMGF6RyXX/G6nCCZQFgp14Bw1pVqIDZy++3X9n 8+HrxMGNjTcO0h7ZJ55+AtUkc/JQsiQq6pUhvWV8ETrn35uFp5slFll+2G+OyCHPBn 1nt/hQyqUGDkAbi27NoKinagMkcKvT0F/EcA4pzU/INsNjkY5cMBb0wRF0NCY32/kU NFMlcPMGQsrpN+1zz2joTDevuX7GODsdkeu6A+wcnozNbNO9x6oDS+ezUrMXz2vut5 NQcaOX8joBZFA== Date: Sat, 18 May 2019 19:57:03 +0300 (EEST) From: =?iso-8859-15?q?Jokke_H=E4m=E4l=E4inen?= To: selinux@vger.kernel.org Subject: [PATCH] conf-parse.y checks (with style fixes removed) Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP diff --git a/libsemanage/src/conf-parse.y b/libsemanage/src/conf-parse.y index b527e893..64b53c2d 100644 --- a/libsemanage/src/conf-parse.y +++ b/libsemanage/src/conf-parse.y @@ -221,6 +221,9 @@ usepasswd: USEPASSWD '=' ARG { ignoredirs: IGNOREDIRS '=' ARG { current_conf->ignoredirs = strdup($3); + if (current_conf->ignoredirs == NULL) { + yyerror("could not allocate memory for current_conf->ignoredirs"); + } free($3); } @@ -240,8 +243,8 @@ handle_unknown: HANDLE_UNKNOWN '=' ARG { bzip_blocksize: BZIP_BLOCKSIZE '=' ARG { int blocksize = atoi($3); free($3); - if (blocksize > 9) - yyerror("bzip-blocksize can only be in the range 0-9"); + if (blocksize < 1 || blocksize > 9) + yyerror("bzip-blocksize can only be in the range 1-9"); else current_conf->bzip_blocksize = blocksize; } @@ -339,9 +342,18 @@ static int semanage_conf_init(semanage_conf_t * conf) { conf->store_type = SEMANAGE_CON_DIRECT; conf->store_path = strdup(basename(selinux_policy_root())); + if (conf->store_path == NULL) { + return -1; + } conf->ignoredirs = NULL; conf->store_root_path = strdup("/var/lib/selinux"); + if (conf->store_root_path == NULL) { + return -1; + } conf->compiler_directory_path = strdup("/usr/libexec/selinux/hll"); + if (conf->compiler_directory_path == NULL) { + return -1; + } conf->policyvers = sepol_policy_kern_vers_max(); conf->target_platform = SEPOL_TARGET_SELINUX; conf->expand_check = 1; @@ -515,7 +527,10 @@ static int parse_module_store(char *arg) } } } - return 0; + + if (current_conf->store_path) + return 0; + return -3; } static int parse_store_root_path(char *arg) @@ -526,6 +541,10 @@ static int parse_store_root_path(char *arg) free(current_conf->store_root_path); current_conf->store_root_path = strdup(arg); + if (current_conf->store_root_path == NULL) { + return -2; + } + return 0; } @@ -536,6 +555,9 @@ static int parse_compiler_path(char *arg) } free(current_conf->compiler_directory_path); current_conf->compiler_directory_path = strdup(arg); + if (current_conf->compiler_directory_path = NULL) { + return -2; + } return 0; }