From: David Laight <david.laight.linux@gmail.com>
To: Usman Akinyemi <usmanakinyemi202@gmail.com>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, james.clark@linaro.org,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
skhan@linuxfoundation.org, linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH] perf/x86: Replace strncpy() with memcpy() for vendor string
Date: Fri, 4 Jul 2025 10:20:07 +0100 [thread overview]
Message-ID: <20250704102007.6354ce9f@pumpkin> (raw)
In-Reply-To: <20250618215843.109941-1-usmanakinyemi202@gmail.com>
On Thu, 19 Jun 2025 03:28:43 +0530
Usman Akinyemi <usmanakinyemi202@gmail.com> wrote:
> 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);
Why not:
cpuid(0, 0, lvl, (void *)vendor, (void *)(vendor + 8), (void *)(vendor + 4));
> vendor[12] = '\0';
> }
>
next prev parent reply other threads:[~2025-07-04 9:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20250704102007.6354ce9f@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=usmanakinyemi202@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).