From patchwork Sat Oct 29 03:07:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 13024479 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 20A3AFA3741 for ; Sat, 29 Oct 2022 03:09:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229766AbiJ2DJh (ORCPT ); Fri, 28 Oct 2022 23:09:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiJ2DJL (ORCPT ); Fri, 28 Oct 2022 23:09:11 -0400 Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80A231C7110; Fri, 28 Oct 2022 20:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1667012944; bh=c8DKeSJHy7nv5V+vv7J8kQrLnkZeHMgYOuYV61olSO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SE3D05l27H4Wqqd9BFHOCeIN7gVyIZ1ITbKps7TVRfxzmKcTqJM9KSpmoXqQuyhEh mWhzsfaF/kPLRKQpJBa1kOSopDaRO75V8NvnSIVXpS9MAQBEbKEYyJ7DQj6gkkAwO0 FV09Ezu8eoBJqxeXRDjTsKo0zbr/teA+ucOR/6YQ= Received: from localhost.localdomain ([111.199.189.86]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id 1EE9CAFF; Sat, 29 Oct 2022 11:07:46 +0800 X-QQ-m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TrxV/sov5fQHhAeOkqM M3h+BAtR+8I9XxdRyjLZNLPquVFOdmZmqAUhJ+CWtKCZKpI/psDeqNa5da9+w= 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: [RESEND PATCH bpf-next] selftests/bpf: Fix strncpy() fortify warning Date: Sat, 29 Oct 2022 11:07:45 +0800 X-OQ-MSGID: <20221029030745.25588-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 e914cc45b766..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)); + enable[0] = '\0'; + strncat(enable, controllers, sizeof(enable) - 1); } snprintf(path, sizeof(path), "%s/cgroup.subtree_control", cgroup_path);