[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_D977F40871CDA0474822CBF7324D25F9B505@qq.com>
Date: Sat, 29 Oct 2022 11:07:45 +0800
From: Rong Tao <rtoax@...mail.com>
To: andrii.nakryiko@...il.com
Cc: andrii@...nel.org, ast@...nel.org, bpf@...r.kernel.org,
daniel@...earbox.net, haoluo@...gle.com, john.fastabend@...il.com,
jolsa@...nel.org, kpsingh@...nel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, martin.lau@...ux.dev,
mykolal@...com, rongtao@...tc.cn, rtoax@...mail.com,
sdf@...gle.com, shuah@...nel.org, song@...nel.org, yhs@...com
Subject: [RESEND PATCH bpf-next] selftests/bpf: Fix strncpy() fortify warning
From: Rong Tao <rongtao@...tc.cn>
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 <rongtao@...tc.cn>
---
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);
--
2.31.1
Powered by blists - more mailing lists