diff mbox series

wifi: ipw2x00: fix -Wformat-truncation warnings

Message ID 20231017165215.143992-1-dmantipov@yandex.ru
State New
Headers show
Series wifi: ipw2x00: fix -Wformat-truncation warnings | expand

Commit Message

Dmitry Antipov Oct. 17, 2023, 4:51 p.m. UTC
Fix the following warnings observed with GCC 13.2 and -Wformat-truncation:

drivers/net/wireless/intel/ipw2x00/ipw2100.c: In function ‘ipw_ethtool_get_drvinfo’:
drivers/net/wireless/intel/ipw2x00/ipw2100.c:5905:63: warning: ‘%s’ directive output
may be truncated writing up to 63 bytes into a region of size 32 [-Wformat-truncation=]
 5905 |         snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
      |                                                               ^~
 5906 |                  fw_ver, priv->eeprom_version, ucode_ver);
      |                  ~~~~~~
drivers/net/wireless/intel/ipw2x00/ipw2100.c:5905:9: note: ‘snprintf’ output between
4 and 140 bytes into a destination of size 32
 5905 |         snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 5906 |                  fw_ver, priv->eeprom_version, ucode_ver);
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For ipw2100, 'ipw2100_get_fwversion()' says that the firmware version
is no longer than 14 bytes, and 'ipw2100_get_ucodeversion()' uses "%08X"
so 10 bytes should be enough.

drivers/net/wireless/intel/ipw2x00/ipw2200.c: In function ‘ipw_ethtool_get_drvinfo’:
drivers/net/wireless/intel/ipw2x00/ipw2200.c:10392:63: warning: ‘%s’ directive output
may be truncated writing up to 63 bytes into a region of size 32 [-Wformat-truncation=]
10392 |         snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
      |                                                               ^~
10393 |                  vers, date);
      |                  ~~~~
drivers/net/wireless/intel/ipw2x00/ipw2200.c:10392:9: note: ‘snprintf’ output between
4 and 98 bytes into a destination of size 32
10392 |         snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10393 |                  vers, date);
      |                  ~~~~~~~~~~~

For ipw2200, I assume that the firmware version is no longer than 14
bytes as well, and, according to ipw2100.h, firmware date is in
'mmm dd yyyy' format so 12 bytes should be enough.

Suggested-by: Kalle Valo <kvalo@kernel.org>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/net/wireless/intel/ipw2x00/ipw2100.c | 2 +-
 drivers/net/wireless/intel/ipw2x00/ipw2200.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Kalle Valo Oct. 20, 2023, 2:50 p.m. UTC | #1
Dmitry Antipov <dmantipov@yandex.ru> wrote:

> Fix the following warnings observed with GCC 13.2 and -Wformat-truncation:
> 
> drivers/net/wireless/intel/ipw2x00/ipw2100.c: In function ‘ipw_ethtool_get_drvinfo’:
> drivers/net/wireless/intel/ipw2x00/ipw2100.c:5905:63: warning: ‘%s’ directive output
> may be truncated writing up to 63 bytes into a region of size 32 [-Wformat-truncation=]
>  5905 |         snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
>       |                                                               ^~
>  5906 |                  fw_ver, priv->eeprom_version, ucode_ver);
>       |                  ~~~~~~
> drivers/net/wireless/intel/ipw2x00/ipw2100.c:5905:9: note: ‘snprintf’ output between
> 4 and 140 bytes into a destination of size 32
>  5905 |         snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  5906 |                  fw_ver, priv->eeprom_version, ucode_ver);
>       |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> For ipw2100, 'ipw2100_get_fwversion()' says that the firmware version
> is no longer than 14 bytes, and 'ipw2100_get_ucodeversion()' uses "%08X"
> so 10 bytes should be enough.
> 
> drivers/net/wireless/intel/ipw2x00/ipw2200.c: In function ‘ipw_ethtool_get_drvinfo’:
> drivers/net/wireless/intel/ipw2x00/ipw2200.c:10392:63: warning: ‘%s’ directive output
> may be truncated writing up to 63 bytes into a region of size 32 [-Wformat-truncation=]
> 10392 |         snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
>       |                                                               ^~
> 10393 |                  vers, date);
>       |                  ~~~~
> drivers/net/wireless/intel/ipw2x00/ipw2200.c:10392:9: note: ‘snprintf’ output between
> 4 and 98 bytes into a destination of size 32
> 10392 |         snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 10393 |                  vers, date);
>       |                  ~~~~~~~~~~~
> 
> For ipw2200, I assume that the firmware version is no longer than 14
> bytes as well, and, according to ipw2100.h, firmware date is in
> 'mmm dd yyyy' format so 12 bytes should be enough.
> 
> Suggested-by: Kalle Valo <kvalo@kernel.org>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>

I tried to fix this a bit differently:

https://patchwork.kernel.org/project/linux-wireless/patch/20231012135854.3473332-2-kvalo@kernel.org/
diff mbox series

Patch

diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2100.c b/drivers/net/wireless/intel/ipw2x00/ipw2100.c
index 0812db8936f1..11b698255fe8 100644
--- a/drivers/net/wireless/intel/ipw2x00/ipw2100.c
+++ b/drivers/net/wireless/intel/ipw2x00/ipw2100.c
@@ -5894,7 +5894,7 @@  static void ipw_ethtool_get_drvinfo(struct net_device *dev,
 				    struct ethtool_drvinfo *info)
 {
 	struct ipw2100_priv *priv = libipw_priv(dev);
-	char fw_ver[64], ucode_ver[64];
+	char fw_ver[16], ucode_ver[10];
 
 	strscpy(info->driver, DRV_NAME, sizeof(info->driver));
 	strscpy(info->version, DRV_VERSION, sizeof(info->version));
diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2200.c b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
index 820100cac491..f9a539d2e93b 100644
--- a/drivers/net/wireless/intel/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
@@ -10377,8 +10377,8 @@  static void ipw_ethtool_get_drvinfo(struct net_device *dev,
 				    struct ethtool_drvinfo *info)
 {
 	struct ipw_priv *p = libipw_priv(dev);
-	char vers[64];
-	char date[32];
+	char vers[16];
+	char date[12];
 	u32 len;
 
 	strscpy(info->driver, DRV_NAME, sizeof(info->driver));