ipv6: replace sprintf() with no format specifiers with strscpy()
Subsystems (4)
PATCH 1/1 ipv6: replace sprintf() with no format specifiers with strscpy()
Multiple instances of sprintf() have no format specifiers. Replace them with strscpy().
--- net/ipv6/ip6_tunnel.c | 2 +- net/ipv6/ip6_vti.c | 2 +- net/ipv6/ip6mr.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/ipv6/ip6_tunnel.c +1 -1
@@ -294,7 +294,7 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p) goto failed;strscpy (name, p->name,IFNAMSIZ ); }else { -sprintf (name,"ip6tnl%%d" ); +strscpy (name,"ip6tnl%d" ,IFNAMSIZ ); } err = -ENOMEM ; dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN,
net/ipv6/ip6_vti.c +1 -1
@@ -210,7 +210,7 @@ static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p goto failed;strscpy (name, p->name,IFNAMSIZ ); }else { -sprintf (name,"ip6_vti%%d" ); +strscpy (name,"ip6_vti%d" ,IFNAMSIZ ); } dev =alloc_netdev (sizeof (*t), name,NET_NAME_UNKNOWN , vti6_dev_setup);
net/ipv6/ip6mr.c +1 -1
@@ -692,7 +692,7 @@ static struct net_device *ip6mr_reg_vif(struct net *net, struct mr_table *mrt)char name[IFNAMSIZ ];if (mrt->id ==RT6_TABLE_DFLT ) -sprintf (name,"pim6reg" ); +strscpy (name,"pim6reg" ,IFNAMSIZ );else sprintf (name,"pim6reg%u" , mrt->id);
Signature · 1 line
2.53.0
Hi Lalit,
Quoted 15 lines · Lalit Shankar Chowdhury
Multiple instances of
sprintf()have no format specifiers. Replace them withstrscpy().Signed-off-by Lalit Shankar Chowdhury <[email protected]>--- net/ipv6/ip6_tunnel.c | 2 +- net/ipv6/ip6_vti.c | 2 +- net/ipv6/ip6mr.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)net/ipv6/ip6_tunnel.c +0
-0
net/ipv6/ip6_tunnel.c static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p) · line 297
Quoted 5 lines
net/ipv6/ip6_tunnel.c +1
-1@@ -294,7 +294,7 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p) goto failed;strscpy (name, p->name,IFNAMSIZ ); }else { -sprintf (name,"ip6tnl%%d" ); +strscpy (name,"ip6tnl%d" ,IFNAMSIZ );
The sprintf() is doing format expansion (%% -> %), the name will be used in __dev_alloc_name() later. I think there is no need to change them.
Thanks
Hangbin
Quoted 15 lines · On Wed, 9 Sep 2026 21:05:52 +0000 Lalit Shankar Chowdhury…
Multiple instances of
sprintf()have no format specifiers. Replace them withstrscpy().Signed-off-by Lalit Shankar Chowdhury <[email protected]>--- net/ipv6/ip6_tunnel.c | 2 +- net/ipv6/ip6_vti.c | 2 +- net/ipv6/ip6mr.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)net/ipv6/ip6_tunnel.c +0
-0
net/ipv6/ip6_tunnel.c static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p) · line 300
Quoted 8 lines
net/ipv6/ip6_tunnel.c +1
-1@@ -294,7 +294,7 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p) goto failed;strscpy (name, p->name,IFNAMSIZ ); }else { -sprintf (name,"ip6tnl%%d" ); +strscpy (name,"ip6tnl%d" ,IFNAMSIZ ); } err = -ENOMEM ; dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN,
That code is silly, there is no need for the copies at all. Something like:
if (p->name[0] && !dev_valid_name[p->name]) return ERR_PTR(-E2BIG); dev = alloc_netdev(sizeof(*t), p->name[0] ? p->name : "op6tnl%d", NET_NAME_UNKNOWN, ip6_tnl_dev_setup); if (!dev) return ERR_PTR(-ENOMEM);
David
Quoted 26 lines
net/ipv6/ip6_vti.c +1
-1@@ -210,7 +210,7 @@ static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p goto failed;strscpy (name, p->name,IFNAMSIZ ); }else { -sprintf (name,"ip6_vti%%d" ); +strscpy (name,"ip6_vti%d" ,IFNAMSIZ ); } dev =alloc_netdev (sizeof (*t), name,NET_NAME_UNKNOWN , vti6_dev_setup);net/ipv6/ip6mr.c +1
-1@@ -692,7 +692,7 @@ static struct net_device *ip6mr_reg_vif(struct net *net, struct mr_table *mrt)char name[IFNAMSIZ ];if (mrt->id ==RT6_TABLE_DFLT ) -sprintf (name,"pim6reg" ); +strscpy (name,"pim6reg" ,IFNAMSIZ );else sprintf (name,"pim6reg%u" , mrt->id);