From patchwork Thu Mar 10 17:17:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Zanussi X-Patchwork-Id: 12776775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53748C433EF for ; Thu, 10 Mar 2022 17:17:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C44AF8D0002; Thu, 10 Mar 2022 12:17:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCD368D0001; Thu, 10 Mar 2022 12:17:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A95C58D0002; Thu, 10 Mar 2022 12:17:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id 97D0A8D0001 for ; Thu, 10 Mar 2022 12:17:11 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 582E78248D52 for ; Thu, 10 Mar 2022 17:17:11 +0000 (UTC) X-FDA: 79229132262.17.3F48041 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id B29E840017 for ; Thu, 10 Mar 2022 17:17:10 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 017DF6127D; Thu, 10 Mar 2022 17:17:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBA2EC340E8; Thu, 10 Mar 2022 17:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646932629; bh=2czeYZEhYrw+eEsPeWClwqc/1LpOrFNLlEfPbHjGD/8=; h=Subject:From:To:Cc:Date:From; b=Fn9iwM4mptqfym/gS03mQe6/YlHfI28Xu6K9Uqc6I47tseIM6F8mztbUfLBRv7kUc SDeea/byD+MHrmOCKTBK81kUBdxUVYbcxQ4NDTkEYAjNG/LaAfZtiHa0zFSuHOnUY+ cSJGXLdEcXAEsXhqJDM5sBtl4qFM7zElXuRZaZhSnqI6vaZCzU0gfITkxMzxXdaYsv yVL+C5/NkoCq1Xv8ujUwsT7suJcRD9k6q8uoaU2ckddpf6BxP1vWDQrPrMdaeuiKSN FtUUhd5OX9aXFn9XPFLvyGhihn2zx7gvixCabXM/9Hs5l2KtTMTHrtgTZjSeJNkK2X yaHSWnD1LqecA== Message-ID: <77deca8cbfd226981b3f1eab203967381e9b5bd9.camel@kernel.org> Subject: [PATCH] tracing: Fix strncpy warning in trace_events_synth.c From: Tom Zanussi To: Steven Rostedt Cc: kernel test robot , kbuild-all@lists.01.org, Linux Memory Management List , linux-kernel@vger.kernel.org Date: Thu, 10 Mar 2022 11:17:07 -0600 X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 X-Rspamd-Queue-Id: B29E840017 X-Stat-Signature: kq3hkbjawesptcww14hhx3uiixg44wuu Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Fn9iwM4m; spf=pass (imf07.hostedemail.com: domain of zanussi@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=zanussi@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646932630-843336 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 0-day reported the strncpy error below: ../kernel/trace/trace_events_synth.c: In function 'last_cmd_set': ../kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length o\ f the source argument [-Wstringop-truncation] 65 | strncpy(last_cmd, str, strlen(str) + 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../kernel/trace/trace_events_synth.c:65:32: note: length computed here 65 | strncpy(last_cmd, str, strlen(str) + 1); | ^~~~~~~~~~~ There's no reason to use strncpy here, in fact there's no reason to do anything but a simple kstrdup() (note we don't even need to check for failure since last_cmod is expected to be either the last cmd string or NULL, and the containing function is a void return). Fixes: 27c888da9867 ("tracing: Remove size restriction on synthetic event cmd error logging") Reported-by: kernel test robot Signed-off-by: Tom Zanussi --- kernel/trace/trace_events_synth.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index fdd79e07e2fc..5e8c07aef071 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -58,11 +58,8 @@ static void last_cmd_set(const char *str) return; kfree(last_cmd); - last_cmd = kzalloc(strlen(str) + 1, GFP_KERNEL); - if (!last_cmd) - return; - strncpy(last_cmd, str, strlen(str) + 1); + last_cmd = kstrdup(str, GFP_KERNEL); } static void synth_err(u8 err_type, u16 err_pos)