public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux-next] relay: use strscpy() is more robust and safer
@ 2022-11-22  0:53 yang.yang29
  2022-11-22  1:07 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: yang.yang29 @ 2022-11-22  0:53 UTC (permalink / raw)
  To: akpm; +Cc: wuchi.zero, axboe, colin.i.king, linux-kernel, xu.panda,
	yang.yang29

From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
 kernel/relay.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/relay.c b/kernel/relay.c
index d7edc934c56d..0a3d2e702001 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -507,7 +507,7 @@ struct rchan *relay_open(const char *base_filename,
 	chan->private_data = private_data;
 	if (base_filename) {
 		chan->has_base_filename = 1;
-		strlcpy(chan->base_filename, base_filename, NAME_MAX);
+		strscpy(chan->base_filename, base_filename, NAME_MAX);
 	}
 	chan->cb = cb;
 	kref_init(&chan->kref);
@@ -578,7 +578,7 @@ int relay_late_setup_files(struct rchan *chan,
 	if (!chan || !base_filename)
 		return -EINVAL;

-	strlcpy(chan->base_filename, base_filename, NAME_MAX);
+	strscpy(chan->base_filename, base_filename, NAME_MAX);

 	mutex_lock(&relay_channels_mutex);
 	/* Is chan already set up? */
-- 
2.15.2

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

* Re: [PATCH linux-next] relay: use strscpy() is more robust and safer
  2022-11-22  0:53 [PATCH linux-next] relay: use strscpy() is more robust and safer yang.yang29
@ 2022-11-22  1:07 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2022-11-22  1:07 UTC (permalink / raw)
  To: yang.yang29; +Cc: wuchi.zero, axboe, colin.i.king, linux-kernel, xu.panda

On Tue, 22 Nov 2022 08:53:25 +0800 (CST) <yang.yang29@zte.com.cn> wrote:

> From: Xu Panda <xu.panda@zte.com.cn>
> 
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.

I really see no benefit to this switch in this situation.  What am I
missing?

But I guess this:

hp2:/usr/src/linux-6.1-rc4> grep -r strlcpy . | wc
    400    1913   34402
hp2:/usr/src/linux-6.1-rc4> grep -r strscpy . | wc 
   2824   11990  266471

is a good enough reason for applying.


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

end of thread, other threads:[~2022-11-22  1:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-22  0:53 [PATCH linux-next] relay: use strscpy() is more robust and safer yang.yang29
2022-11-22  1:07 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox