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>
This commit is contained in:
parent
c6e29fe5e0
commit
c7109c72ab
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue