Commit c7109c72 authored by Bo Liu's avatar Bo Liu Committed by Greg Kroah-Hartman

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: default avatarBo Liu <liubo03@inspur.com>
Link: https://lore.kernel.org/r/20230118012944.2436-1-liubo03@inspur.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c6e29fe5
...@@ -1666,9 +1666,8 @@ static void handle_control_message(struct virtio_device *vdev, ...@@ -1666,9 +1666,8 @@ static void handle_control_message(struct virtio_device *vdev,
"Not enough space to store port name\n"); "Not enough space to store port name\n");
break; break;
} }
strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), strscpy(port->name, buf->buf + buf->offset + sizeof(*cpkt),
name_size - 1); name_size);
port->name[name_size - 1] = 0;
/* /*
* Since we only have one sysfs attribute, 'name', * Since we only have one sysfs attribute, 'name',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment