* [PATCH] hwmon: (pmbus/core) Replace deprecated strncpy() with strscpy()
@ 2025-02-27 17:39 Thorsten Blum
2025-02-27 22:37 ` Guenter Roeck
2025-03-02 16:29 ` Guenter Roeck
0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-02-27 17:39 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, Jerome Brunet, Patryk Biel,
Ninad Palsule, Peter Zijlstra, Patrick Rudolph
Cc: Thorsten Blum, linux-hardening, linux-hwmon, linux-kernel
strncpy() is deprecated for NUL-terminated destination buffers; use
strscpy() instead.
Compile-tested only.
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/hwmon/pmbus/pmbus_core.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 787683e83db6..cdde8b03a6e9 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -1470,8 +1470,7 @@ static int pmbus_add_label(struct pmbus_data *data,
snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq);
if (!index) {
if (phase == 0xff)
- strncpy(label->label, lstring,
- sizeof(label->label) - 1);
+ strscpy(label->label, lstring);
else
snprintf(label->label, sizeof(label->label), "%s.%d",
lstring, phase);
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (pmbus/core) Replace deprecated strncpy() with strscpy()
2025-02-27 17:39 [PATCH] hwmon: (pmbus/core) Replace deprecated strncpy() with strscpy() Thorsten Blum
@ 2025-02-27 22:37 ` Guenter Roeck
2025-02-28 8:33 ` Thorsten Blum
2025-03-02 16:29 ` Guenter Roeck
1 sibling, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2025-02-27 22:37 UTC (permalink / raw)
To: Thorsten Blum, Jean Delvare, Jerome Brunet, Patryk Biel,
Ninad Palsule, Peter Zijlstra, Patrick Rudolph
Cc: linux-hardening, linux-hwmon, linux-kernel
On 2/27/25 09:39, Thorsten Blum wrote:
> strncpy() is deprecated for NUL-terminated destination buffers; use
> strscpy() instead.
>
> Compile-tested only.
>
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/hwmon/pmbus/pmbus_core.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 787683e83db6..cdde8b03a6e9 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -1470,8 +1470,7 @@ static int pmbus_add_label(struct pmbus_data *data,
> snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq);
> if (!index) {
> if (phase == 0xff)
> - strncpy(label->label, lstring,
> - sizeof(label->label) - 1);
> + strscpy(label->label, lstring);
What guarantees that strlen(lstring) < sizeof(label->label) ?
Guenter
> else
> snprintf(label->label, sizeof(label->label), "%s.%d",
> lstring, phase);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (pmbus/core) Replace deprecated strncpy() with strscpy()
2025-02-27 22:37 ` Guenter Roeck
@ 2025-02-28 8:33 ` Thorsten Blum
0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-02-28 8:33 UTC (permalink / raw)
To: Guenter Roeck
Cc: Jean Delvare, Jerome Brunet, Patryk Biel, Ninad Palsule,
Peter Zijlstra, Patrick Rudolph, linux-hardening, linux-hwmon,
linux-kernel
On 27. Feb 2025, at 23:37, Guenter Roeck wrote:
> On 2/27/25 09:39, Thorsten Blum wrote:
>> strncpy() is deprecated for NUL-terminated destination buffers; use
>> strscpy() instead.
>> Compile-tested only.
>> Link: https://github.com/KSPP/linux/issues/90
>> Cc: linux-hardening@vger.kernel.org
>> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
>> ---
>
> What guarantees that strlen(lstring) < sizeof(label->label) ?
Hi Guenter, I don't think it matters for this patch.
If lstring >= label, strscpy() behaves the same as strncpy() because the
size argument is now one byte larger.
If lstring < label, strscpy() NUL-terminates the destination buffer, but
doesn't add NUL-padding compared to strncpy(). However, this doesn't
matter because label is already zero-initialized.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (pmbus/core) Replace deprecated strncpy() with strscpy()
2025-02-27 17:39 [PATCH] hwmon: (pmbus/core) Replace deprecated strncpy() with strscpy() Thorsten Blum
2025-02-27 22:37 ` Guenter Roeck
@ 2025-03-02 16:29 ` Guenter Roeck
1 sibling, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2025-03-02 16:29 UTC (permalink / raw)
To: Thorsten Blum
Cc: Jean Delvare, Jerome Brunet, Patryk Biel, Ninad Palsule,
Peter Zijlstra, Patrick Rudolph, linux-hardening, linux-hwmon,
linux-kernel
On Thu, Feb 27, 2025 at 06:39:33PM +0100, Thorsten Blum wrote:
> strncpy() is deprecated for NUL-terminated destination buffers; use
> strscpy() instead.
>
> Compile-tested only.
>
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Applied.
> ---
> drivers/hwmon/pmbus/pmbus_core.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 787683e83db6..cdde8b03a6e9 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -1470,8 +1470,7 @@ static int pmbus_add_label(struct pmbus_data *data,
> snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq);
> if (!index) {
> if (phase == 0xff)
> - strncpy(label->label, lstring,
> - sizeof(label->label) - 1);
> + strscpy(label->label, lstring);
I added a note explaining that strscpy() uses sizeof(label->label) if the
length of the destination buffer is not provided.
Guenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-02 16:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 17:39 [PATCH] hwmon: (pmbus/core) Replace deprecated strncpy() with strscpy() Thorsten Blum
2025-02-27 22:37 ` Guenter Roeck
2025-02-28 8:33 ` Thorsten Blum
2025-03-02 16:29 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox