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

From: Thomas Huth

Date: Mon Sep 28 2026 - 02:26:27 EST


On 26/09/2026 07.58, Thorsten Blum wrote:
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@xxxxxxxxxx>
---
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) {

Reviewed-by: Thomas Huth <thuth@xxxxxxxxxx>