From patchwork Thu Dec 1 10:58:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maninder Singh X-Patchwork-Id: 9455847 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 C6FDC60515 for ; Thu, 1 Dec 2016 11:06:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF52E284A2 for ; Thu, 1 Dec 2016 11:06:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A218D284CE; Thu, 1 Dec 2016 11:06:27 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C0A2284A2 for ; Thu, 1 Dec 2016 11:06:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cCP9n-0004Zt-B8; Thu, 01 Dec 2016 11:04:03 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cCP9i-0004PO-Ec for linux-arm-kernel@lists.infradead.org; Thu, 01 Dec 2016 11:03:59 +0000 Received: from epcpsbgm1new.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OHI00DA86PXLU20@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 01 Dec 2016 20:03:34 +0900 (KST) X-AuditID: cbfee61a-f79916d0000062de-5a-5840038632a9 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id 63.CC.25310.68300485; Thu, 1 Dec 2016 20:03:34 +0900 (KST) Received: from localhost.localdomain ([107.108.92.210]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OHI0089Z6PSG860@mmp1.samsung.com>; Thu, 01 Dec 2016 20:03:34 +0900 (KST) From: Maninder Singh To: bcousson@baylibre.com, paul@pwsan.com, tony@atomide.com, linux@armlinux.org.uk Subject: [PATCH v2] mach-omap2: fixing wrong strcat for Non-NULL terminated string Date: Thu, 01 Dec 2016 16:28:33 +0530 Message-id: <1480589913-8839-1-git-send-email-maninder1.s@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsVy+t9jAd02ZocIg59PZC1evJrAYnFn/l9W i02Pr7FaXN41h81i9pJ+FotDU/cyWhye38Zice/NViaLDzv+Mlvsv+JlcejkXEYHbo/L1y4y e3z7OonF4/2NVnaPzUvqPW787mX36NuyitHj8ya5APYoN5uM1MSU1CKF1Lzk/JTMvHRbpdAQ N10LJYW8xNxUW6UIXd+QICWFssScUiDPyAANODgHuAcr6dsluGVM7O1mLnjDVbFs2immBsYW zi5GTg4JAROJ49cnskHYYhIX7q0Hs4UEljJKtN9w7WLkArJ/MkpcuvqVFSTBJqAnsWrXHhYQ W0QgRGLb843MIEXMAg8ZJe78uQDkcHAIAyWO3RQCqWERUJXoXfSICcTmFXCT6Dq6mRVimZzE yWOTWScwci9gZFjFKJFakFxQnJSea5iXWq5XnJhbXJqXrpecn7uJERzaz6R2MB7c5X6IUYCD UYmHd0GcfYQQa2JZcWXuIUYJDmYlEd6N/4FCvCmJlVWpRfnxRaU5qcWHGE2BDpjILCWanA+M u7ySeEMTcxNzYwMLc0tLEyMlcd7G2c/ChQTSE0tSs1NTC1KLYPqYODilGhi9O4qD8s/5HA88 0nLXvVVz2oSzK6Qs6ufyhcne4ZpYNTuudepF+wXruOWumYv+/du1TU364YeMrcv1I3jCvI+v tGC1mB0t9Un14PkveZxN3c1Hld4YNS390Oj603fnvpzsIoe7O2VefVaS9Z02YeGsk1Vx03IN bEMTdcrd7rlIPDc77e6os1qJpTgj0VCLuag4EQAoyT86gwIAAA== X-MTR: 20000000000000000@CPGS X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161201_030358_937040_A8BB4955 X-CRM114-Status: GOOD ( 11.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vaneet Narang , linux-kernel@vger.kernel.org, ajeet.y@samsung.com, Maninder Singh , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, pankaj.m@samsung.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP variable name can have Non NULL terminated string after cropping which may result strcat to fail, and cropping is not required if (strlen(oh->name) + 8 < MOD_CLK_MAX_NAME_LEN). Issue caught with static analysis tool: "Dangerous usage of 'name' (strncpy doesn't always 0-terminate it)" Signed-off-by: Vaneet Narang Signed-off-by: Maninder Singh --- v1 -> v2: changed strncpy to strlcpy arch/arm/mach-omap2/omap_hwmod.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index 759e1d4..582b95a 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -742,12 +742,14 @@ static int _init_main_clk(struct omap_hwmod *oh) char name[MOD_CLK_MAX_NAME_LEN]; struct clk *clk; - /* +7 magic comes from '_mod_ck' suffix */ - if (strlen(oh->name) + 7 > MOD_CLK_MAX_NAME_LEN) + /* +8 magic comes from strlen("_mod_ck") added as suffix */ + if (strlen(oh->name) + 8 > MOD_CLK_MAX_NAME_LEN) { pr_warn("%s: warning: cropping name for %s\n", __func__, oh->name); + strlcpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - 7); + } else + strcpy(name, oh->name); - strncpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - 7); strcat(name, "_mod_ck"); clk = clk_get(NULL, name);