net: tun: fix strscpy call with missing size argument
Subsystems (3)
PATCH 1/1 net: tun: fix strscpy call with missing size argument
The tun_set_iff() and tun_get_iff() functions call strscpy() with only two arguments, omitting the destination buffer size.
This patch corrects these calls by providing the required size argument using the IFNAMSIZ macro. This ensures the code adheres to the function's documented contract and improves its overall robustness and clarity.
--- drivers/net/tun.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/tun.c +2 -2
@@ -2823,13 +2823,13 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)if (netif_running (tun->dev))netif_tx_wake_all_queues (tun->dev); -strscpy (ifr->ifr_name, tun->dev->name); +strscpy (ifr->ifr_name, tun->dev->name,IFNAMSIZ );return 0 ; }static void tun_get_iff (struct tun_struct *tun,struct ifreq *ifr) { -strscpy (ifr->ifr_name, tun->dev->name); +strscpy (ifr->ifr_name, tun->dev->name,IFNAMSIZ ); ifr->ifr_flags =tun_flags (tun);
Signature · 1 line
2.47.3
Willem de Bruijn
maintainerQuoted 11 lines · Zhang Tengfei
The
tun_set_iff()andtun_get_iff()functions callstrscpy()with only two arguments, omitting the destination buffer size.This patch corrects these calls by providing the required size argument using the IFNAMSIZ macro. This ensures the code adheres to the function's documented contract and improves its overall robustness and clarity.
Fixes a57384110dc6 ("tun: replace strcpy with strscpy for ifr_name")Signed-off-by Zhang Tengfei <[email protected]>
The two argument choice is intentional. In that case the length is taken from the struct field sizes, which is more robust than an explicit argument.
https://lore.kernel.org/netdev/[email protected]/
Quoted 27 lines
--- drivers/net/tun.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/tun.c +2
-3@@ -2823,13 +2823,13 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)if (netif_running (tun->dev))netif_tx_wake_all_queues (tun->dev); -strscpy (ifr->ifr_name, tun->dev->name); +strscpy (ifr->ifr_name, tun->dev->name,IFNAMSIZ );return 0 ; }static void tun_get_iff (struct tun_struct *tun,struct ifreq *ifr) { -strscpy (ifr->ifr_name, tun->dev->name); +strscpy (ifr->ifr_name, tun->dev->name,IFNAMSIZ ); ifr->ifr_flags =tun_flags (tun); --2.47.3