Re: [PATCH] qede: Prevent possible snprintf() truncation by bounding %s string format
From: Baran TUna
Date: Wed Jul 01 2026 - 12:23:49 EST
The current solution is pretty arbitrary.
Numbers are coming from a simple calculation, to make sure output always fits.
I will take a further look and send a patch if there is a more generalized solution.
On 7/1/26 6:27 PM, Breno Leitao wrote:
On Wed, Jul 01, 2026 at 05:47:11PM +0300, Baran Tuna wrote:
GCC warning shows that formatted strings mayWhere is this 16 coming from?
exceed the fixed-size destination buffers.
Bounding the %s string format
so the maximum formatted output always fits.
This eliminates the -Wformat-truncation warning.
Signed-off-by: Baran Tuna <barant@xxxxxxxxxxxx>
---
drivers/net/ethernet/qlogic/qede/qede_ethtool.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
index 647f30a16a94..5428f53150a0 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
@@ -618,10 +618,10 @@ static void qede_get_drvinfo(struct net_device *ndev,
if ((strlen(storm) + strlen("[storm]")) <
sizeof(info->version))
snprintf(info->version, sizeof(info->version),
- "[storm %s]", storm);
+ "[storm %.16s]", storm);
Also, isn't the if above checking for no overflow? I.e,
we got here only if strlen(storm) + strlen("[storm]") < sizeof(info->version))
For whoever else is reviwewing this, this the buffers:
#define ETHTOOL_FWVERS_LEN 32
char version[32];
char storm[ETHTOOL_FWVERS_LEN];