[<prev] [next>] [day] [month] [year] [list]
Message-ID: <202212051938026789359@zte.com.cn>
Date: Mon, 5 Dec 2022 19:38:02 +0800 (CST)
From: <yang.yang29@....com.cn>
To: <amit@...nel.org>
Cc: <arnd@...db.de>, <virtualization@...ts.linux-foundation.org>,
<linux-kernel@...r.kernel.org>, <xu.panda@....com.cn>,
<yang.yang29@....com.cn>
Subject: [PATCH linux-next] virtio_console: use strscpy to instead of strncpy()
From: Xu Panda <xu.panda@....com.cn>
The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL terminated strings.
Signed-off-by: Xu Panda <xu.panda@....com.cn>
Signed-off-by: Yang Yang <yang.yang29@....com>
---
drivers/char/virtio_console.c | 5 ++---
1 file 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',
--
2.15.2
Powered by blists - more mailing lists