relay: use strscpy() is more robust and safer
authorXu Panda <xu.panda@zte.com.cn>
Tue, 22 Nov 2022 00:53:25 +0000 (08:53 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 12 Dec 2022 03:30:18 +0000 (19:30 -0800)
The implementation of strscpy() is more robust and safer.  That's now the
recommended way to copy NUL terminated strings.

Link: https://lkml.kernel.org/r/202211220853259244666@zte.com.cn
Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: wuchi <wuchi.zero@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/relay.c

index d7edc93..0a3d2e7 100644 (file)
@@ -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? */