* [PATCH] net: niu: fix potential buffer overflow/truncation in irq names
@ 2026-07-25 14:11 Ronan Marchal
0 siblings, 0 replies; only message in thread
From: Ronan Marchal @ 2026-07-25 14:11 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel,
ronanmarchal29
Building with W=1 reports a -Wformat-truncation warning on
niu_set_irq_name(): the "%s:SYSERR" format could be truncated
because irq_name[] was one byte too small for the worst case
interface name length (IFNAMSIZ-1) plus the ":SYSERR" suffix.
Also replace the remaining sprintf() calls in the same function
with snprintf() to guard against buffer overflow, consistent with
the rest of the function.
Signed-off-by: Ronan Marchal <ronanmarchal29@gmail.com>
---
drivers/net/ethernet/sun/niu.c | 6 +++---
drivers/net/ethernet/sun/niu.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c
index 88df15e6dd74..54dd7281191d 100644
--- a/drivers/net/ethernet/sun/niu.c
+++ b/drivers/net/ethernet/sun/niu.c
@@ -6021,11 +6021,11 @@ static void niu_set_irq_name(struct niu *np)
int port = np->port;
int i, j = 1;
- sprintf(np->irq_name[0], "%s:MAC", np->dev->name);
+ snprintf(np->irq_name[0], sizeof(np->irq_name[0]), "%s:MAC", np->dev->name);
if (port == 0) {
- sprintf(np->irq_name[1], "%s:MIF", np->dev->name);
- sprintf(np->irq_name[2], "%s:SYSERR", np->dev->name);
+ snprintf(np->irq_name[1], sizeof(np->irq_name[1]), "%s:MIF", np->dev->name);
+ snprintf(np->irq_name[2], sizeof(np->irq_name[2]), "%s:SYSERR", np->dev->name);
j = 3;
}
diff --git a/drivers/net/ethernet/sun/niu.h b/drivers/net/ethernet/sun/niu.h
index d8368043fc3b..676d31499ac3 100644
--- a/drivers/net/ethernet/sun/niu.h
+++ b/drivers/net/ethernet/sun/niu.h
@@ -3262,7 +3262,7 @@ struct niu {
#define NIU_FLAGS_XMAC 0x00010000 /* 0=BMAC 1=XMAC */
u32 msg_enable;
- char irq_name[NIU_NUM_RXCHAN+NIU_NUM_TXCHAN+3][IFNAMSIZ + 6];
+ char irq_name[NIU_NUM_RXCHAN + NIU_NUM_TXCHAN + 3][IFNAMSIZ + 7];
/* Protects hw programming, and ring state. */
spinlock_t lock;
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-25 14:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-25 14:11 [PATCH] net: niu: fix potential buffer overflow/truncation in irq names Ronan Marchal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox