Skip to contentSkip to conversation

eth: bnxt: fix string truncation warning in FW version

PATCH Applied Jakub Kicinski 3 participants 3 messages Jan 17, 2025 – Jan 19, 2025

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 eth: bnxt: fix string truncation warning in FW version

W=1 builds with gcc 14.2.1 report:

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:4193:32: error: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size 27 [-Werror=format-truncation=]
4193 | "/pkg %s", buf);

It's upset that we let buf be full length but then we use 5 characters for "/pkg ".

The builds is also clear with clang version 19.1.5 now.

---
CC: [email protected]
CC: [email protected]

---
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +1 -1
index 540c140d52dc..65a20931c579 100644
@@ -4184,7 +4184,7 @@ int bnxt_get_pkginfo(struct net_device *dev, char *ver, int size)
 static void bnxt_get_pkgver(struct net_device *dev)
 {
 	struct bnxt *bp = netdev_priv(dev);
-	char buf[FW_VER_STR_LEN];
+	char buf[FW_VER_STR_LEN - 5];
 	int len;
 
 	if (!bnxt_get_pkginfo(dev, buf, sizeof(buf))) {
Signature · 1 line
2.48.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jakub Kicinski

W=1 builds with gcc 14.2.1 report:

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:4193:32: error: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size 27 [-Werror=format-truncation=]
4193 | "/pkg %s", buf);

Quoted 6 lines

It's upset that we let buf be full length but then we use 5 characters for "/pkg ".

The builds is also clear with clang version 19.1.5 now.

There is actually more truncation because of the string before "/pkg ". Since this works,

#2 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 17 Jan 2025 10:37:26 -0800 you wrote:

W=1 builds with gcc 14.2.1 report:

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:4193:32: error: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size 27 [-Werror=format-truncation=]
4193 | "/pkg %s", buf);

It's upset that we let buf be full length but then we use 5 characters for "/pkg ".

[...]

Here is the summary with links:
- [net-next] eth: bnxt: fix string truncation warning in FW version

    https://git.kernel.org/netdev/net-next/c/17656eb5cfe5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html