Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Bo Liu and committed by
Greg Kroah-Hartman
c7109c72 c6e29fe5

+2 -3
+2 -3
drivers/char/virtio_console.c
··· 1666 1666 "Not enough space to store port name\n"); 1667 1667 break; 1668 1668 } 1669 - strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), 1670 - name_size - 1); 1671 - port->name[name_size - 1] = 0; 1669 + strscpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), 1670 + name_size); 1672 1671 1673 1672 /* 1674 1673 * Since we only have one sysfs attribute, 'name',