2023-10-20 14:52:10

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH] wifi: ipw2x00: fix -Wformat-truncation warnings

Dmitry Antipov <[email protected]> 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 <[email protected]>
> Signed-off-by: Dmitry Antipov <[email protected]>

I tried to fix this a bit differently:

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches