From: Thorsten Blum <thorsten.blum@linux.dev>
To: Petr Pavlu <petr.pavlu@suse.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
"Shyam Saini" <shyamsaini@linux.microsoft.com>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Dmitry Antipov" <dmantipov@yandex.ru>,
linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org
Subject: Re: [PATCH] params: Replace deprecated strcpy() with strscpy()
Date: Wed, 13 Aug 2025 14:15:50 +0200 [thread overview]
Message-ID: <47F53A47-D331-4DC5-8146-7ED09C65177F@linux.dev> (raw)
In-Reply-To: <f0a77c72-8fad-4fc5-9198-2a9c7c97a489@suse.com>
On 13. Aug 2025, at 13:42, Petr Pavlu wrote:
> On 8/13/25 11:33 AM, Thorsten Blum wrote:
>> On 13. Aug 2025, at 10:59, Petr Pavlu wrote:
>>> Since the code already calculated the length of val and that it fits
>>> into kps->string, is there any advantage (or disadvantage) to using
>>> strscpy() over memcpy()?
>>
>> strscpy() guarantees that the destination buffer 'kps->string' is always
>> NUL-terminated, even if the source 'val' is not. memcpy() just copies
>> the bytes as they are.
>>
>> If it were guaranteed that 'val' is always NUL-terminated, memcpy()
>> would be fine too, but since param_set_copystring() is exported, we
>> probably can't make that assumption.
>
> The function param_set_copystring() checks using
> 'strnlen(val, kps->maxlen) == kps->maxlen' if val contains NUL in the
> first kps->maxlen bytes. It can use memcpy() instead of strscpy() to
> avoid repeating this work.
I see, and yes
memcpy(kps->string, val, len + 1);
would then be slightly more efficient because strscpy() would just
recompute the length before calling memcpy() internally.
I'll submit a v2.
Thanks,
Thorsten
prev parent reply other threads:[~2025-08-13 12:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-10 21:44 Thorsten Blum
2025-08-13 8:59 ` Petr Pavlu
2025-08-13 9:33 ` Thorsten Blum
2025-08-13 11:42 ` Petr Pavlu
2025-08-13 12:15 ` Thorsten Blum [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=47F53A47-D331-4DC5-8146-7ED09C65177F@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=dmantipov@yandex.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=mcgrof@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=shyamsaini@linux.microsoft.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
all inboxes | Powered by JetHome®