summaryrefslogtreecommitdiffstats
path: root/drivers/char/virtio_console.c
diff options
context:
space:
mode:
authorBo Liu <liubo03@inspur.com>2023-01-18 02:29:44 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-01-20 13:07:54 +0100
commitc7109c72ab92dd6934b9ff8d45cb7e86f7a7ba0d (patch)
treed75ceb21f352d75f4e651cdcf380b5b8fdf0d1e9 /drivers/char/virtio_console.c
parentipack: ipoctal: remove unnecessary (void*) conversions (diff)
downloadlinux-c7109c72ab92dd6934b9ff8d45cb7e86f7a7ba0d.tar.xz
linux-c7109c72ab92dd6934b9ff8d45cb7e86f7a7ba0d.zip
virtio_console: Use strscpy() to instead of strncpy()
The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL-terminated strings. Signed-off-by: Bo Liu <liubo03@inspur.com> Link: https://lore.kernel.org/r/20230118012944.2436-1-liubo03@inspur.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/char/virtio_console.c')
-rw-r--r--drivers/char/virtio_console.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 6a821118d553..d5ac4d955bc8 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1666,9 +1666,8 @@ static void handle_control_message(struct virtio_device *vdev,
"Not enough space to store port name\n");
break;
}
- strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt),
- name_size - 1);
- port->name[name_size - 1] = 0;
+ strscpy(port->name, buf->buf + buf->offset + sizeof(*cpkt),
+ name_size);
/*
* Since we only have one sysfs attribute, 'name',