Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753383AbcLHEQD (ORCPT ); Wed, 7 Dec 2016 23:16:03 -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 X-AuditID: cbfee61a-f79916d0000062de-51-5848de71c6ad 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-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1455 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 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)) { -- 1.9.1