From: kendrajmoore <kendra.j.moore3443@gmail.com>
To: linux-pm@vger.kernel.org
Cc: lenb@kernel.org, linux-kernel@vger.kernel.org,
Kendra Moore <kendra.j.moore3443@gmail.com>
Subject: [PATCH] Replace strncpy with strscpy to ensure null-termination
Date: Sun, 23 Mar 2025 10:31:11 -0400 [thread overview]
Message-ID: <20250323143111.79886-1-kendra.j.moore3443@gmail.com> (raw)
From: Kendra Moore <kendra.j.moore3443@gmail.com>
The field pcounter->name is used as a null-terminated string.
Using strncpy() with ARRAY_SIZE - 1 does not guarantee
null-termination and can lead to undefined behavior if the source
is too long.
This patch replaces it with strscpy() which ensures
null-termination and returns an error code if truncation occurs.
Signed-off-by: Kendra Moore <kendra.j.moore3443@gmail.com>
---
tools/power/x86/turbostat/turbostat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 8d5011a0bf60..8f24e18d3de0 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -9345,7 +9345,7 @@ int pmt_add_counter(unsigned int guid, unsigned int seq, const char *name, enum
}
if (new_counter) {
- strncpy(pcounter->name, name, ARRAY_SIZE(pcounter->name) - 1);
+ strscpy(pcounter->name, name, ARRAY_SIZE(pcounter->name));
pcounter->type = type;
pcounter->scope = scope;
pcounter->lsb = lsb;
--
2.39.5
next reply other threads:[~2025-03-23 14:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-23 14:31 kendrajmoore [this message]
2025-06-08 14:59 ` Len Brown
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=20250323143111.79886-1-kendra.j.moore3443@gmail.com \
--to=kendra.j.moore3443@gmail.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.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
all inboxes | Powered by JetHome®