From patchwork Wed Dec 19 11:45:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 10737099 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 93D7A1399 for ; Wed, 19 Dec 2018 11:45:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82AFC2AE76 for ; Wed, 19 Dec 2018 11:45:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71B5C2AFA3; Wed, 19 Dec 2018 11:45:08 +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=-7.9 required=2.0 tests=BAYES_00,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 6D4672AE76 for ; Wed, 19 Dec 2018 11:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727494AbeLSLpH (ORCPT ); Wed, 19 Dec 2018 06:45:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44526 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726774AbeLSLpH (ORCPT ); Wed, 19 Dec 2018 06:45:07 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB5DA753F1 for ; Wed, 19 Dec 2018 11:45:06 +0000 (UTC) Received: from workstation.brq.redhat.com (unknown [10.43.12.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4C7D5DE8B; Wed, 19 Dec 2018 11:45:03 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH] mcstrans: Fix check in raw_color() Date: Wed, 19 Dec 2018 12:45:00 +0100 Message-Id: <20181219114500.22113-1-plautrba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 19 Dec 2018 11:45:07 +0000 (UTC) Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP raw_color() uses color_str as an output argument which is assigned to a new allocated memory. Therefore it should fail when color_str is null; or when *color_str is not null in order to avoid a memory leak. Fixes: >>> selinux.selinux_raw_context_to_color('system_u:system_r:inetd_t:s0') Traceback (most recent call last): File "", line 1, in OSError: [Errno 0] Error Signed-off-by: Petr Lautrbach Acked-by: Nicolas Iooss --- mcstrans/src/mcscolor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcstrans/src/mcscolor.c b/mcstrans/src/mcscolor.c index cc6174bb..6ea1aa97 100644 --- a/mcstrans/src/mcscolor.c +++ b/mcstrans/src/mcscolor.c @@ -292,7 +292,7 @@ int raw_color(const security_context_t raw, char **color_str) { size_t result_size = (N_COLOR * CHARS_PER_COLOR) + 1; int rc = -1; - if (!color_str || !*color_str) { + if (!color_str || *color_str) { return -1; }