Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751100AbcLEFcX (ORCPT ); Mon, 5 Dec 2016 00:32:23 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:34599 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750751AbcLEFcU (ORCPT ); Mon, 5 Dec 2016 00:32:20 -0500 X-AuditID: cbfee61a-f79916d0000062de-6d-5844fbe257a3 From: Maninder Singh To: bcousson@baylibre.com, paul@pwsan.com, tony@atomide.com, linux@armlinux.org.uk Cc: 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: 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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1466 Lines: 42 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)) { -- 1.9.1