From: Michael Estner <michaelestner@web.de>
To: qmo@kernel.org, ast@kernel.org, daniel@iogearbox.net
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org,
Michael Estner <michaelestner@web.de>
Subject: [PATCH] bpftool: Replace strncpy with strscpy
Date: Fri, 28 Feb 2025 19:18:27 +0100 [thread overview]
Message-ID: <20250228181827.90436-1-michaelestner@web.de> (raw)
strncpy() is deprecated for NUL-terminated destination buffers. Use
strscpy() instead and remove the manual NUL-termination.
Compile-tested only.
Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: Michael Estner <michaelestner@web.de>
---
tools/bpf/bpftool/xlated_dumper.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c
index d0094345fb2b..60dbe48a91a3 100644
--- a/tools/bpf/bpftool/xlated_dumper.c
+++ b/tools/bpf/bpftool/xlated_dumper.c
@@ -135,8 +135,7 @@ print_insn_json(void *private_data, const char *fmt, ...)
va_start(args, fmt);
if (l > 0) {
- strncpy(chomped_fmt, fmt, l - 1);
- chomped_fmt[l - 1] = '\0';
+ strscpy(chomped_fmt, fmt);
}
jsonw_vprintf_enquote(json_wtr, chomped_fmt, args);
va_end(args);
--
2.25.1
next reply other threads:[~2025-02-28 18:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 18:18 Michael Estner [this message]
2025-02-28 21:37 ` [PATCH] bpftool: Replace strncpy with strscpy Quentin Monnet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250228181827.90436-1-michaelestner@web.de \
--to=michaelestner@web.de \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qmo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox