From patchwork Thu Dec 8 04:10:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maninder Singh X-Patchwork-Id: 9465743 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 B11C96071E for ; Thu, 8 Dec 2016 04:18:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 905BB2850D for ; Thu, 8 Dec 2016 04:18:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84AA228515; Thu, 8 Dec 2016 04:18:58 +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 151E02850D for ; Thu, 8 Dec 2016 04:18:57 +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 1cEq8D-00051W-8x; Thu, 08 Dec 2016 04:16:29 +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 1cEq87-0004nV-KL for linux-arm-kernel@lists.infradead.org; Thu, 08 Dec 2016 04:16:25 +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 <0OHU009KCMI62U30@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 08 Dec 2016 13:15:45 +0900 (KST) X-AuditID: cbfee61a-f79916d0000062de-51-5848de71c6ad Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id F6.22.25310.17ED8485; Thu, 8 Dec 2016 13:15:45 +0900 (KST) Received: from localhost.localdomain ([107.108.92.210]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OHU0055ZMI31220@mmp2.samsung.com>; Thu, 08 Dec 2016 13:15:45 +0900 (KST) From: Maninder Singh To: bcousson@baylibre.com, paul@pwsan.com, tony@atomide.com Subject: [PATCH v3] mach-omap2: fixing wrong strcat for Non-NULL terminated string Date: Thu, 08 Dec 2016 09:40:30 +0530 Message-id: <1481170230-2120-1-git-send-email-maninder1.s@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrILMWRmVeSWpSXmKPExsVy+t9jQd3Cex4RBj9Xi1i8eDWBxeLO/L+s FpseX2O1uLxrDpvF7CX9LBaHpu5ltDg8v43F4t6brUwWH3b8ZbbYf8XL4tDJuYwO3B6Xr11k 9vj2dRKLx/sbrewem5fUe9z43cvu0bdlFaPH501yAexRbjYZqYkpqUUKqXnJ+SmZeem2SqEh broWSgp5ibmptkoRur4hQUoKZYk5pUCekQEacHAOcA9W0rdLcMvo2XuUpeA2d8W2uddYGxjv c3YxcnJICJhItD7oZoewxSQu3FvP1sXIxSEkMItR4tOLu4wQzk9GibbTSxhBqtgE9CRW7drD AmKLCFhLTNlxnhWkiFngF6PE+a2tYAlhgRCJhftXsIHYLAKqEs8ffwCKc3DwCrhJfPplAbFN TuLkscmsExi5FzAyrGKUSC1ILihOSs81zEst1ytOzC0uzUvXS87P3cQIDu5nUjsYD+5yP8Qo wMGoxMMr0O0RIcSaWFZcmXuIUYKDWUmEt/ouUIg3JbGyKrUoP76oNCe1+BCjKdD+icxSosn5 wMjLK4k3NDE3MTc2sDC3tDQxUhLnbZz9LFxIID2xJDU7NbUgtQimj4mDU6qBcWGOUHjc5+Bj ti55/S0d8xmY5IriU/tb1rjdPX4zcMOiLfdvsq+1ObKzo+TEVrb0zKN907a9uNvryntF/QKD IuusLX96+r69dD/t0fkxfdmk7bczlx+y6PM7niLs+rwk6Qr7jHMTlU7bP+sMmH//laB+ye4d V5a+n32bda7eXZfpH3Zpnb+9/I4SS3FGoqEWc1FxIgBkqOKhhAIAAA== X-MTR: 20000000000000000@CPGS X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161207_201623_912315_E9CF5E45 X-CRM114-Status: GOOD ( 12.04 ) 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@armlinux.org.uk, 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 Issue caught with static analysis tool: "Dangerous usage of 'name' (strncpy doesn't always 0-terminate it)" Use strlcpy _includes_ the NUL terminator, and strlcat() which ensures that it won't overflow the buffer. Reported-by: Maninder Singh Signed-off-by: Vaneet Narang CC: Russell King --- v1 -> v2: changed strncpy to strlcpy v2 -> v3: use of strlcat as suggested by Russell to make change clearer and simpler. arch/arm/mach-omap2/omap_hwmod.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index 759e1d4..e8b9887 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -741,14 +741,14 @@ static int _init_main_clk(struct omap_hwmod *oh) int ret = 0; char name[MOD_CLK_MAX_NAME_LEN]; struct clk *clk; + static const char modck[] = "_mod_ck"; - /* +7 magic comes from '_mod_ck' suffix */ - if (strlen(oh->name) + 7 > MOD_CLK_MAX_NAME_LEN) + if (strlen(oh->name) >= MOD_CLK_MAX_NAME_LEN - strlen(modck)) pr_warn("%s: warning: cropping name for %s\n", __func__, oh->name); - strncpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - 7); - strcat(name, "_mod_ck"); + strlcpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - strlen(modck)); + strlcat(name, modck, MOD_CLK_MAX_NAME_LEN); clk = clk_get(NULL, name); if (!IS_ERR(clk)) {