Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934164AbcK3Kp3 (ORCPT ); Wed, 30 Nov 2016 05:45:29 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:34932 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932789AbcK3KpS (ORCPT ); Wed, 30 Nov 2016 05:45:18 -0500 X-AuditID: cbfee61a-f79916d0000062de-f4-583eadba3217 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, ajeet.y@samsung.com, pankaj.m@samsung.com, Maninder Singh , Vaneet Narang Subject: [PATCH 1/1] mach-omap2: fixing wrong strcat for Non-NULL terminated string Date: Wed, 30 Nov 2016 16:10:28 +0530 Message-id: <1480502428-19509-1-git-send-email-maninder1.s@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsVy+t9jQd3da+0iDOa+ZbV48WoCi8Wd+X9Z LTY9vsZqcXnXHDaL2Uv6WSwOTd3LaHF4fhuLxb03W5ksPuz4y2yx/4qXxaGTcxkduD0uX7vI 7PHt6yQWj/c3Wtk9Ni+p97jxu5fdo2/LKkaPz5vkAtij3GwyUhNTUosUUvOS81My89JtlUJD 3HQtlBTyEnNTbZUidH1DgpQUyhJzSoE8IwM04OAc4B6spG+X4JZx7KhewSeuiu79a1gaGLs4 uxg5OSQETCReNd1igbDFJC7cW88GYgsJzGKUONnhA2H/ZJR4sSsXxGYT0JNYtWsPWL2IQIjE tucbmbsYuTiYBR4yStz5c4EZJCEsECrRta0DzGYRUJXYMu092FBeAXeJ6dfboJbJSZw8Npl1 AiP3AkaGVYwSqQXJBcVJ6bmGeanlesWJucWleel6yfm5mxjBgf1MagfjwV3uhxgFOBiVeHgn 9NlGCLEmlhVX5h5ilOBgVhLhjV9jFyHEm5JYWZValB9fVJqTWnyI0RTogInMUqLJ+cCoyyuJ NzQxNzE3NrAwt7Q0MVIS522c/SxcSCA9sSQ1OzW1ILUIpo+Jg1OqgbGttEre/knS06lH1HuN P4lf1fDWf6bIYPQleDZvs43G9Jj/LjM51CbOZmHlnf2dgbfFf9Ien2p3nokOH035nn88En2x SPFMa4DfdrlHAh3fFz9M4y3irZ4lW/wo9v7kHOHlexUmWjqukSqsWN1vLbA+Z871dPcm3Xs5 L2Jakv0+bj/8yvv7bCWW4oxEQy3mouJEANGDpHiCAgAA X-MTR: 20000000000000000@CPGS Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1354 Lines: 38 variable name can have Non NULL terminated string after cropping which may result strcat to fail, and cropping is not required if (strlen(oh->name) + 8 < MOD_CLK_MAX_NAME_LEN). Issue caught with static analysis tool: "Dangerous usage of 'name' (strncpy doesn't always 0-terminate it)" Signed-off-by: Vaneet Narang Signed-off-by: Maninder Singh --- arch/arm/mach-omap2/omap_hwmod.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index 759e1d4..8adf272 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -742,12 +742,15 @@ static int _init_main_clk(struct omap_hwmod *oh) char name[MOD_CLK_MAX_NAME_LEN]; struct clk *clk; - /* +7 magic comes from '_mod_ck' suffix */ - if (strlen(oh->name) + 7 > MOD_CLK_MAX_NAME_LEN) + /* +8 magic comes from strlen("_mod_ck") added as suffix */ + if (strlen(oh->name) + 8 > MOD_CLK_MAX_NAME_LEN) { pr_warn("%s: warning: cropping name for %s\n", __func__, oh->name); + strncpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - 8); + name[MOD_CLK_MAX_NAME_LEN - 8] = '\0'; + } else + strcpy(name, oh->name); - strncpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - 7); strcat(name, "_mod_ck"); clk = clk_get(NULL, name); -- 1.9.1