linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf/x86: Replace strncpy() with memcpy() for vendor string
@ 2025-06-18 21:58 Usman Akinyemi
  2025-07-02 18:53 ` Usman Akinyemi
  2025-07-04  9:20 ` David Laight
  0 siblings, 2 replies; 8+ messages in thread
From: Usman Akinyemi @ 2025-06-18 21:58 UTC (permalink / raw)
  To: peterz, mingo, acme, namhyung
  Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
	kan.liang, james.clark, linux-perf-users, linux-kernel, skhan,
	linux-kernel-mentees

strncpy() is unsafe for fixed-size binary data as
it may not NUL-terminate and is deprecated for such
usage. Since we're copying raw CPUID register values,
memcpy() is the correct and safe choice.

Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
---
 tools/perf/arch/x86/util/header.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c
index 412977f8aa83..43ba55627817 100644
--- a/tools/perf/arch/x86/util/header.c
+++ b/tools/perf/arch/x86/util/header.c
@@ -16,9 +16,9 @@ void get_cpuid_0(char *vendor, unsigned int *lvl)
 	unsigned int b, c, d;
 
 	cpuid(0, 0, lvl, &b, &c, &d);
-	strncpy(&vendor[0], (char *)(&b), 4);
-	strncpy(&vendor[4], (char *)(&d), 4);
-	strncpy(&vendor[8], (char *)(&c), 4);
+	memcpy(&vendor[0], (char *)(&b), 4);
+	memcpy(&vendor[4], (char *)(&d), 4);
+	memcpy(&vendor[8], (char *)(&c), 4);
 	vendor[12] = '\0';
 }
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-23  1:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-18 21:58 [PATCH] perf/x86: Replace strncpy() with memcpy() for vendor string Usman Akinyemi
2025-07-02 18:53 ` Usman Akinyemi
2025-07-04  9:20 ` David Laight
2025-07-04 10:31   ` Usman Akinyemi
2025-07-04 11:10   ` James Clark
2025-07-04 12:47     ` Usman Akinyemi
2025-07-10 13:33       ` Usman Akinyemi
2025-07-23  1:37         ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).