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: 9465741 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 A692B6071E for ; Thu, 8 Dec 2016 04:16:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F4762850D for ; Thu, 8 Dec 2016 04:16:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83CA128515; Thu, 8 Dec 2016 04:16:19 +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=-6.9 required=2.0 tests=BAYES_00,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 387C52850D for ; Thu, 8 Dec 2016 04:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752956AbcLHEQC (ORCPT ); Wed, 7 Dec 2016 23:16:02 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:44163 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751091AbcLHEQB (ORCPT ); Wed, 7 Dec 2016 23:16:01 -0500 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>; 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 Cc: linux@armlinux.org.uk, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, pankaj.m@samsung.com, ajeet.y@samsung.com, Maninder Singh , Vaneet Narang 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 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.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)) {