[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250619144934348-KObAuS33g0yI9ulIjMjE@zte.com.cn>
Date: Thu, 19 Jun 2025 14:49:34 +0800 (CST)
From: <jiang.peng9@....com.cn>
To: <pabeni@...hat.com>
Cc: <davem@...emloft.net>, <edumazet@...gle.com>, <kuba@...nel.org>,
<horms@...nel.org>, <jiang.peng9@....com.cn>, <jiri@...nulli.us>,
<linux@...blig.org>, <oscmaes92@...il.com>, <netdev@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <xu.xin16@....com.cn>,
<yang.yang29@....com.cn>
Subject: [PATCH net] net: vlan: fix format-truncation warnings in
register_vlan_device
From: Peng Jiang <jiang.peng9@....com.cn>
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@....com.cn>
---
net/8021q/vlan.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 06908e37c3d9..f2c17035f625 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -217,7 +217,7 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
struct vlan_dev_priv *vlan;
struct net *net = dev_net(real_dev);
struct vlan_net *vn = net_generic(net, vlan_net_id);
- char name[IFNAMSIZ];
+ char name[IFNAMSIZ + 6]; /* plus extra 6 bytes for vlan_id */
int err;
if (vlan_id >= VLAN_VID_MASK)
@@ -232,26 +232,26 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
switch (vn->name_type) {
case VLAN_NAME_TYPE_RAW_PLUS_VID:
/* name will look like: eth1.0005 */
- snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
+ snprintf(name, sizeof(name), "%s.%.4i", real_dev->name, vlan_id);
break;
case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
/* Put our vlan.VID in the name.
* Name will look like: vlan5
*/
- snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);
+ snprintf(name, sizeof(name), "vlan%i", vlan_id);
break;
case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
/* Put our vlan.VID in the name.
* Name will look like: eth0.5
*/
- snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
+ snprintf(name, sizeof(name), "%s.%i", real_dev->name, vlan_id);
break;
case VLAN_NAME_TYPE_PLUS_VID:
/* Put our vlan.VID in the name.
* Name will look like: vlan0005
*/
default:
- snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);
+ snprintf(name, sizeof(name), "vlan%.4i", vlan_id);
}
new_dev = alloc_netdev(sizeof(struct vlan_dev_priv), name,
--
2.25.1
<div class="zcontentRow"><p>From: Peng Jiang <jiang.peng9@....com.cn><br></p><p><br></p><p>Building with W=1 triggers format-truncation warnings in the</p><p>register_vlan_device function when compiled with GCC 12.3.0.</p><p>These warnings occur due to the use of %i and %.4i format</p><p>specifiers with a buffer size that might be insufficient</p><p>for the formatted string, potentially causing truncation.</p><p><br></p><p>The original warning trace:</p><p>net/8021q/vlan.c:247:17: note: 'snprintf' output between 3 and 22 bytes into a destination of size 16</p><p>247 | snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);</p><p><br></p><p>Signed-off-by: Peng Jiang <jiang.peng9@....com.cn></p><p>---</p><p> net/8021q/vlan.c | 10 +++++-----</p><p> 1 file changed, 5 insertions(+), 5 deletions(-)</p><p><br></p><p>diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c</p><p>index 06908e37c3d9..f2c17035f625 100644</p><p>--- a/net/8021q/vlan.c</p><p>+++ b/net/8021q/vlan.c</p><p>@@ -217,7 +217,7 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)</p><p> struct vlan_dev_priv *vlan;</p><p> struct net *net = dev_net(real_dev);</p><p> struct vlan_net *vn = net_generic(net, vlan_net_id);</p><p>- char name[IFNAMSIZ];</p><p>+ char name[IFNAMSIZ + 6]; /* plus extra 6 bytes for vlan_id */</p><p> int err;</p><p> </p><p> if (vlan_id >= VLAN_VID_MASK)</p><p>@@ -232,26 +232,26 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)</p><p> switch (vn->name_type) {</p><p> case VLAN_NAME_TYPE_RAW_PLUS_VID:</p><p> /* name will look like: eth1.0005 */</p><p>- snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);</p><p>+ snprintf(name, sizeof(name), "%s.%.4i", real_dev->name, vlan_id);</p><p> break;</p><p> case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:</p><p> /* Put our vlan.VID in the name.</p><p> * Name will look like: vlan5</p><p> */</p><p>- snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);</p><p>+ snprintf(name, sizeof(name), "vlan%i", vlan_id);</p><p> break;</p><p> case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:</p><p> /* Put our vlan.VID in the name.</p><p> * Name will look like: eth0.5</p><p> */</p><p>- snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);</p><p>+ snprintf(name, sizeof(name), "%s.%i", real_dev->name, vlan_id);</p><p> break;</p><p> case VLAN_NAME_TYPE_PLUS_VID:</p><p> /* Put our vlan.VID in the name.</p><p> * Name will look like: vlan0005</p><p> */</p><p> default:</p><p>- snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);</p><p>+ snprintf(name, sizeof(name), "vlan%.4i", vlan_id);</p><p> }</p><p> </p><p> new_dev = alloc_netdev(sizeof(struct vlan_dev_priv), name,</p><p>-- </p><p>2.25.1</p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p></div>
Powered by blists - more mailing lists