Re: [PATCH net] net: vlan: fix format-truncation warnings in? register_vlan_device
From: Simon Horman
Date: Thu Jun 19 2025 - 08:36:46 EST
On Thu, Jun 19, 2025 at 02:49:34PM +0800, jiang.peng9@xxxxxxxxxx wrote:
> From: Peng Jiang <jiang.peng9@xxxxxxxxxx>
>
> Building with W=1 triggers format-truncation warnings in the
> register_vlan_device function when compiled with GCC 12.3.0.
> These warnings occur due to the use of %i and %.4i format
> specifiers with a buffer size that might be insufficient
> for the formatted string, potentially causing truncation.
>
> The original warning trace:
> net/8021q/vlan.c:247:17: note: 'snprintf' output between 3 and 22 bytes into a destination of size 16
> 247 | snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
>
> Signed-off-by: Peng Jiang <jiang.peng9@xxxxxxxxxx>
Hi Peng Jiang,
name is passed to alloc_netdev(). Which is a wrapper around alloc_netdev_mqs()
which includes the following check:
BUG_ON(strlen(name) >= sizeof(dev->name));
And the size of dev->name is IFNAMSIZ.
So while I am very pleased to see efforts to address format-truncation
warning - indeed I have made efforts elsewhere to this end myself - I don't
think we can solve this problem the way you propose.
Also, I suspect any work in this area will not be a bug fix, and
thus more appropriate to target at net-next rather than net.
Subject; [PATCH net-next]
And please make sure patches for net or next-next apply against
their target tree: this patch applies to cleanly to neither.
For more information on process for networking patches please see
https://docs.kernel.org/process/maintainer-netdev.html
--
pw-bot: changes-requested
...