From patchwork Sat Oct 29 02:59:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 13024473 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FA65FA3741 for ; Sat, 29 Oct 2022 03:02:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbiJ2DCX (ORCPT ); Fri, 28 Oct 2022 23:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbiJ2DCS (ORCPT ); Fri, 28 Oct 2022 23:02:18 -0400 Received: from out203-205-221-233.mail.qq.com (out203-205-221-233.mail.qq.com [203.205.221.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2C3C391; Fri, 28 Oct 2022 20:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1667012474; bh=yzgljApEq0qdIxlgB5hEgOKNze+VaVoW3rIffIgUM7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=u8XStJ/mQtG2DbJzqxABEYYRn3RnlpfZl4iB5O2tysvAKpTEzinx5DO6fFT47PnV/ t8wNRmmYDdmUkQfLKLL9JT1QwqXIFRfwVBN6mtGRuiBk3lEXbbIlhVYIzRNmM3ii94 jjbz40kaf8w6MdmWABToAENaGwbigjC+QEhpkRpk= Received: from localhost.localdomain ([111.199.189.86]) by newxmesmtplogicsvrszc1-0.qq.com (NewEsmtp) with SMTP id EF589CDA; Sat, 29 Oct 2022 10:59:53 +0800 X-QQ-mid: xmsmtpt1667012393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4a0ll93s= From: Rong Tao To: andrii.nakryiko@gmail.com Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, martin.lau@linux.dev, mykolal@fb.com, rongtao@cestc.cn, rtoax@foxmail.com, sdf@google.com, shuah@kernel.org, song@kernel.org, yhs@fb.com Subject: [PATCH bpf-next] selftests/bpf: Fix strncpy() fortify warning Date: Sat, 29 Oct 2022 10:59:52 +0800 X-OQ-MSGID: <20221029025952.22566-1-rtoax@foxmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Rong Tao Replace strncpy() with strncat(), strncat() leaves the dst string zero terminated. Compile samples/bpf warning: $ cd samples/bpf $ make ... In function ‘__enable_controllers’: samples/bpf/../../tools/testing/selftests/bpf/cgroup_helpers.c:80:17: warning: ‘strncpy’ specified bound 4097 equals destination size [-Wstringop-truncation] 80 | strncpy(enable, controllers, sizeof(enable)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Rong Tao --- tools/testing/selftests/bpf/cgroup_helpers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c index a70e873b267e..912e6522c7c5 100644 --- a/tools/testing/selftests/bpf/cgroup_helpers.c +++ b/tools/testing/selftests/bpf/cgroup_helpers.c @@ -77,7 +77,8 @@ static int __enable_controllers(const char *cgroup_path, const char *controllers enable[len] = 0; close(fd); } else { - strncpy(enable, controllers, sizeof(enable) - 1); + enable[0] = '\0'; + strncat(enable, controllers, sizeof(enable) - 1); } snprintf(path, sizeof(path), "%s/cgroup.subtree_control", cgroup_path);