[PATCH v2] scsi: proc: use snprintf() for the host name
From: shao.mingyin
Date: Tue Nov 10 2026 - 10:20:14 EST
From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
scsi_proc_host_add() and scsi_proc_host_rm() format shost->host_no into
a 10-byte buffer with sprintf(). host_no is an unsigned int and can
reach ten digits. The %d output plus the terminator then overflows the
buffer, and a bounded format would truncate a ten-digit number to nine
digits, colliding with an existing procfs entry.
Widen the buffer to 11 bytes, use snprintf(), and print with %u to
match the type. Ten-digit host numbers are written in full, the
overflow is gone, and W=1 no longer reports -Wformat-truncation.
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Link: https://lore.kernel.org/all/sashiko-outbox-204381@xxxxxxxxxx/
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
v2:
- widen name[] to 11 bytes so a ten-digit host_no is not truncated
to nine digits and cannot collide with an existing procfs entry
- print host_no with %u, matching its unsigned int type
v1: https://lore.kernel.org/all/20261109113810258gK5WuYWQKt0HsI2ikxmHo@xxxxxxxxxx/
drivers/scsi/scsi_proc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index fdc355d783da366dcdce21949d9a20e43be474fa..6a4324c2e2b5d26c65b9860ca4048210e6044fb7 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -221,7 +221,7 @@ void scsi_proc_host_add(struct Scsi_Host *shost)
const struct scsi_host_template *sht = shost->hostt;
struct scsi_proc_entry *e;
struct proc_dir_entry *p;
- char name[10];
+ char name[11];
if (!sht->show_info)
return;
@@ -230,7 +230,7 @@ void scsi_proc_host_add(struct Scsi_Host *shost)
if (!e)
goto err;
- sprintf(name,"%d", shost->host_no);
+ snprintf(name, sizeof(name), "%u", shost->host_no);
p = proc_create_data(name, S_IRUGO | S_IWUSR, e->proc_dir,
&proc_scsi_ops, shost);
if (!p)
@@ -251,7 +251,7 @@ void scsi_proc_host_rm(struct Scsi_Host *shost)
{
const struct scsi_host_template *sht = shost->hostt;
struct scsi_proc_entry *e;
- char name[10];
+ char name[11];
if (!sht->show_info)
return;
@@ -260,7 +260,7 @@ void scsi_proc_host_rm(struct Scsi_Host *shost)
if (!e)
return;
- sprintf(name,"%d", shost->host_no);
+ snprintf(name, sizeof(name), "%u", shost->host_no);
remove_proc_entry(name, e->proc_dir);
}
/**
--
2.27.0