relay: use strscpy() is more robust and safer
PATCH 1/1 relay: use strscpy() is more robust and safer
From: Xu Panda <[email protected]>
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 <[email protected]>
Signed-off-by Yang Yang <[email protected]>
--- kernel/relay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/relay.c +2 -2
@@ -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? */
Signature · 1 line
2.15.2
Andrew Morton
maintainerQuoted 4 lines · On Tue, 22 Nov 2022 08:53:25 +0800 (CST) <[email protected]> wrote:
From: Xu Panda <[email protected]>
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.