Re: drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c:1833:4: warning: 'snprintf' will always be truncated; specified size is 80, but format string expands to at least 94

From: Nathan Chancellor
Date: Fri Jan 12 2024 - 14:47:36 EST


On Wed, Jan 10, 2024 at 10:55:22PM +0800, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: ab27740f76654ed58dd32ac0ba0031c18a6dea3b
> commit: 70f0302b3f2053b64a6a653a76a20cb95438dc85 net/mlx5: Bridge, implement mdb offload
> date: 9 months ago
> config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20240110/202401102205.XmxWrS5y-lkp@xxxxxxxxx/config)
> compiler: clang version 18.0.0git (https://github.com/llvm/llvm-project 7e186d366d6c7def0543acc255931f617e76dff0)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240110/202401102205.XmxWrS5y-lkp@xxxxxxxxx/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202401102205.XmxWrS5y-lkp@xxxxxxxxx/
>
> All warnings (new ones prefixed by >>):
>
> >> drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c:1833:4: warning: 'snprintf' will always be truncated; specified size is 80, but format string expands to at least 94 [-Wformat-truncation-non-kprintf]
> 1833 | NL_SET_ERR_MSG_FMT_MOD(extack,
> | ^
> include/linux/netlink.h:130:2: note: expanded from macro 'NL_SET_ERR_MSG_FMT_MOD'
> 130 | NL_SET_ERR_MSG_FMT((extack), KBUILD_MODNAME ": " fmt, ##args)
> | ^
> include/linux/netlink.h:115:6: note: expanded from macro 'NL_SET_ERR_MSG_FMT'
> 115 | if (snprintf(__extack->_msg_buf, NETLINK_MAX_FMTMSG_LEN, \
> | ^
> 1 warning generated.

I have not looked to see if this is a legitimate issue or not, as clang
does not understand the kernel's special %p modifiers, so it is a little
hard to tell at first glance. For this reason, I sent a patch turning
off the -non-kprintf warnings but it has not been picked up yet:

https://lore.kernel.org/20231002-disable-wformat-truncation-overflow-non-kprintf-v1-1-35179205c8d9@xxxxxxxxxx/

Cheers,
Nathan