From: David Laight <david.laight.linux@gmail.com>
To: Melih Emik <melihemik@noirlang.tr>
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] platform/x86: replace strcpy() with strscpy()
Date: Mon, 11 May 2026 21:44:51 +0100 [thread overview]
Message-ID: <20260511214451.5741692b@pumpkin> (raw)
In-Reply-To: <20260506175031.25337-1-melihemik@noirlang.tr>
On Wed, 6 May 2026 20:50:31 +0300
Melih Emik <melihemik@noirlang.tr> wrote:
> Replace strcpy() with strscpy() in dell_rbu to use the preferred
> kernel string API for bounded copies.
I think I'm going to find that recommendation and change it :-)
For copies of constant strings into arrays it is actually slightly
better to use strcpy().
There is a subtle difference if the string is too long.
strscpy() will truncate it whereas you'll get a compile-time error
for strcpy().
Normally both calls result in a call to memcpy().
Which can get converted to writes on constants.
You are much better off looking for non-constant strcpy(), strcat()
and strlcat() call.
Once all the 'variable' strcpy() calls have gone the header can be
changed to error and new ones while still allowing strcpy() of quoted
strings into arrays - so there is no need to get rid of them at all.
-- David
>
> The destination buffer size is known at compile time
>
> (sizeof(image_type)), so this conversion is safe.
>
> No functional change intended.
>
> Signed-off-by: Melih Emik <melihemik@noirlang.tr>
> ---
> drivers/platform/x86/dell/dell_rbu.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/dell/dell_rbu.c b/drivers/platform/x86/dell/dell_rbu.c
> index 3fa9de9aa47b..85eea8898fac 100644
> --- a/drivers/platform/x86/dell/dell_rbu.c
> +++ b/drivers/platform/x86/dell/dell_rbu.c
> @@ -562,9 +562,9 @@ static ssize_t image_type_write(struct file *filp, struct kobject *kobj,
> buffer[count] = '\0';
>
> if (strstr(buffer, "mono"))
> - strcpy(image_type, "mono");
> + strscpy(image_type, "mono", sizeof(image_type));
> else if (strstr(buffer, "packet"))
> - strcpy(image_type, "packet");
> + strscpy(image_type, "packet", sizeof(image_type));
> else if (strstr(buffer, "init")) {
> /*
> * If due to the user error the driver gets in a bad
prev parent reply other threads:[~2026-05-11 20:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 17:50 [PATCH] platform/x86: replace strcpy() with strscpy() Melih Emik
2026-05-11 16:45 ` Ilpo Järvinen
2026-05-11 19:19 ` Melih Emik
2026-05-11 20:44 ` David Laight [this message]
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=20260511214451.5741692b@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=melihemik@noirlang.tr \
--cc=platform-driver-x86@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