Thread (7 messages) 7 messages, 5 authors, 15d ago

[PATCH 2/2] hwrng: virtio - use snprintf() in probe_common()

flat view
COLD15d

From: Thorsten Blum <blum@kernel.org>
Date: 2026-09-26 05:59:35
Also in: linux-crypto, lkml
Subsystem: hardware random number generator core, the rest, virtio rng driver · Maintainers: Olivia Mackall, Herbert Xu, Linus Torvalds, Laurent Vivier

While the current code works correctly, replace the unbounded sprintf()
with the safer snprintf() to follow secure coding best practices.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/char/hw_random/virtio-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 5b1b23b5596a..f9982217247d 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -162,7 +162,7 @@ static int probe_common(struct virtio_device *vdev)
 		err = index;
 		goto err_ida;
 	}
-	sprintf(vi->name, "virtio_rng.%d", index);
+	snprintf(vi->name, sizeof(vi->name), "virtio_rng.%d", vi->index);
 	init_completion(&vi->have_data);
 
 	vi->hwrng = (struct hwrng) {
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help