From patchwork Wed Nov 30 10:40:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maninder Singh X-Patchwork-Id: 9453971 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 B488F6071E for ; Wed, 30 Nov 2016 10:48:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D708128429 for ; Wed, 30 Nov 2016 10:48:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA5052842E; Wed, 30 Nov 2016 10:48:59 +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 D757228429 for ; Wed, 30 Nov 2016 10:48:58 +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 1cC2Q5-0001x5-Jg; Wed, 30 Nov 2016 10:47:21 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cC2OS-0007yj-1v for linux-arm-kernel@lists.infradead.org; Wed, 30 Nov 2016 10:45:43 +0000 Received: from epcpsbgm1new.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OHG00C2VB7BGBD0@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 30 Nov 2016 19:45:15 +0900 (KST) X-AuditID: cbfee61a-f79916d0000062de-f4-583eadba3217 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id 47.06.25310.ABDAE385; Wed, 30 Nov 2016 19:45:15 +0900 (KST) Received: from localhost.localdomain ([107.108.92.210]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OHG000YDB7A5N80@mmp2.samsung.com>; Wed, 30 Nov 2016 19:45:14 +0900 (KST) From: Maninder Singh To: bcousson@baylibre.com, paul@pwsan.com, tony@atomide.com, linux@armlinux.org.uk 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161130_024540_565872_BD34DB08 X-CRM114-Status: GOOD ( 12.10 ) 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 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);