efc_node_update_display_name() concatenates two strings into
node->display_name, which is EFC_NAME_LENGTH (32) bytes, with
snprintf(node->display_name, sizeof(node->display_name), "%s.%s",
nport->display_name, portid_display);
Both sources are declared as 32-byte arrays, so the format string allows
up to 31 + 1 + 31 bytes. With W=1 gcc reports:
efc_node.c:254:70: warning: '%s' directive output may be truncated
writing up to 15 bytes into a region of size between 0 and 31
[-Wformat-truncation=]
In practice the inputs are far shorter: nport->display_name is either
"s%06x" (7 characters) or "------", and portid_display is at most 6
characters, so the result never exceeds 14 characters. Adding the
precision states that bound in the format string and makes the
concatenation fit the buffer by construction.
No functional change.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/all/202502182036.RChzXKS8-lkp@intel.com/
Signed-off-by: xujiahao <xujiahao@cmss.chinamobile.com>
---
drivers/scsi/elx/libefc/efc_node.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/elx/libefc/efc_node.c b/drivers/scsi/elx/libefc/efc_node.c
index f17e052fe..f4bdeb79e 100644
--- a/drivers/scsi/elx/libefc/efc_node.c
+++ b/drivers/scsi/elx/libefc/efc_node.c
@@ -251,7 +251,7 @@ efc_node_update_display_name(struct efc_node *node)
efc_node_fcid_display(port_id, portid_display, sizeof(portid_display));
- snprintf(node->display_name, sizeof(node->display_name), "%s.%s",
+ snprintf(node->display_name, sizeof(node->display_name), "%.15s.%.15s",
nport->display_name, portid_display);
}
--
2.43.0