Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755521AbcLALDj (ORCPT ); Thu, 1 Dec 2016 06:03:39 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:40559 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750847AbcLALDh (ORCPT ); Thu, 1 Dec 2016 06:03:37 -0500 X-AuditID: cbfee61a-f79916d0000062de-5a-5840038632a9 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 v2] mach-omap2: fixing wrong strcat for Non-NULL terminated string Date: Thu, 01 Dec 2016 16:28:33 +0530 Message-id: <1480589913-8839-1-git-send-email-maninder1.s@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsVy+t9jAd02ZocIg59PZC1evJrAYnFn/l9W i02Pr7FaXN41h81i9pJ+FotDU/cyWhye38Zice/NViaLDzv+Mlvsv+JlcejkXEYHbo/L1y4y e3z7OonF4/2NVnaPzUvqPW787mX36NuyitHj8ya5APYoN5uM1MSU1CKF1Lzk/JTMvHRbpdAQ N10LJYW8xNxUW6UIXd+QICWFssScUiDPyAANODgHuAcr6dsluGVM7O1mLnjDVbFs2immBsYW zi5GTg4JAROJ49cnskHYYhIX7q0Hs4UEljJKtN9w7WLkArJ/MkpcuvqVFSTBJqAnsWrXHhYQ W0QgRGLb843MIEXMAg8ZJe78uQDkcHAIAyWO3RQCqWERUJXoXfSICcTmFXCT6Dq6mRVimZzE yWOTWScwci9gZFjFKJFakFxQnJSea5iXWq5XnJhbXJqXrpecn7uJERzaz6R2MB7c5X6IUYCD UYmHd0GcfYQQa2JZcWXuIUYJDmYlEd6N/4FCvCmJlVWpRfnxRaU5qcWHGE2BDpjILCWanA+M u7ySeEMTcxNzYwMLc0tLEyMlcd7G2c/ChQTSE0tSs1NTC1KLYPqYODilGhi9O4qD8s/5HA88 0nLXvVVz2oSzK6Qs6ufyhcne4ZpYNTuudepF+wXruOWumYv+/du1TU364YeMrcv1I3jCvI+v tGC1mB0t9Un14PkveZxN3c1Hld4YNS390Oj603fnvpzsIoe7O2VefVaS9Z02YeGsk1Vx03IN bEMTdcrd7rlIPDc77e6os1qJpTgj0VCLuag4EQAoyT86gwIAAA== X-MTR: 20000000000000000@CPGS Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1348 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 --- v1 -> v2: changed strncpy to strlcpy arch/arm/mach-omap2/omap_hwmod.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index 759e1d4..582b95a 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -742,12 +742,14 @@ 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); + strlcpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - 7); + } 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