From patchwork Mon Dec 5 05:27:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maninder Singh X-Patchwork-Id: 9460311 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 7BBE560236 for ; Mon, 5 Dec 2016 05:36:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D23725D97 for ; Mon, 5 Dec 2016 05:36:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F4492621D; Mon, 5 Dec 2016 05:36:30 +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 AF8C225D97 for ; Mon, 5 Dec 2016 05:36:29 +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 1cDltQ-0000P9-0x; Mon, 05 Dec 2016 05:32:48 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDltL-0000Lt-Dv for linux-arm-kernel@lists.infradead.org; Mon, 05 Dec 2016 05:32:44 +0000 Received: from epcpsbgm1new.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OHP01A5N61DE9A0@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Mon, 05 Dec 2016 14:32:18 +0900 (KST) X-AuditID: cbfee61a-f79916d0000062de-6d-5844fbe257a3 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id F7.00.25310.2EBF4485; Mon, 5 Dec 2016 14:32:18 +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 <0OHP00HDA61HIS40@mmp1.samsung.com>; Mon, 05 Dec 2016 14:32:18 +0900 (KST) From: Maninder Singh To: bcousson@baylibre.com, paul@pwsan.com, tony@atomide.com, linux@armlinux.org.uk Subject: [PATCH v3] mach-omap2: fixing wrong strcat for Non-NULL terminated string Date: Mon, 05 Dec 2016 10:57:13 +0530 Message-id: <1480915633-16284-1-git-send-email-maninder1.s@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsVy+t9jAd1Hv10iDNa0y1i8eDWBxeLO/L+s FpseX2O1uLxrDpvF7CX9LBaHpu5ltDg8v43F4t6brUwWH3b8ZbbYf8XL4tDJuYwO3B6Xr11k 9vj2dRKLx/sbrewem5fUe9z43cvu0bdlFaPH501yAexRbjYZqYkpqUUKqXnJ+SmZeem2SqEh broWSgp5ibmptkoRur4hQUoKZYk5pUCekQEacHAOcA9W0rdLcMuY/GE6e8Ez7orJd7+wNTC+ 4uxi5OSQEDCROPq8lRnCFpO4cG89G4gtJLCUUWLzQscuRi4g+yejxPS2H+wgCTYBPYlVu/aw gNgiAiES255vBGtmFnjIKHH8ay6ILQwUX7h/BdggFgFVieY9t8FsXgF3iaajTewQy+QkTh6b zDqBkXsBI8MqRonUguSC4qT0XMO81HK94sTc4tK8dL3k/NxNjODQfia1g/HgLvdDjAIcjEo8 vB0uLhFCrIllxZW5hxglOJiVRHhlvwOFeFMSK6tSi/Lji0pzUosPMZoCHTCRWUo0OR8Yd3kl 8YYm5ibmxgYW5paWJkZK4ryNs5+FCwmkJ5akZqemFqQWwfQxcXBKNTAuazp5Il5o/vv5e/1u Bz0Q/+1kmF8acEa6kHfuGaVCF/7wJQv83l+9+pD9+4Olfw5I349Vt/58mb89jilAcObis0md X827GYRWJ5dtLdE7wR029+KdFn0d1l3Cf6eby7Rkrs0OesEd+iee9WrIWSfT6BOZL7uY+Zcm M2eev9l30LP/avlfw3VKLMUZiYZazEXFiQBZ1AyEgwIAAA== X-MTR: 20000000000000000@CPGS X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161204_213243_649315_7CA98409 X-CRM114-Status: GOOD ( 12.21 ) 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 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 Signed-off-by: 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)) {