Skip to contentSkip to conversation

virtio_console: Use strscpy() to instead of strncpy()

PATCH New Bo Liu 1 participant 1 message Jan 18, 2023

Subsystems (2)
lore
Share & tools
lore

Bo Liu

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/char/virtio_console.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/char/virtio_console.c +2 -3
index 6a821118d553..d5ac4d955bc8 100644
@@ -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',
Signature · 1 line
2.27.0