[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231213011840.10005-1-luoxueqin@kylinos.cn>
Date: Wed, 13 Dec 2023 09:18:40 +0800
From: xueqin Luo <luoxueqin@...inos.cn>
To: gregkh@...uxfoundation.org, hdegoede@...hat.com,
Larry.Finger@...inger.net
Cc: xiongxin@...inos.cn, wangqi@...inos.cn,
linux-kernel@...r.kernel.org, linux-staging@...ts.linux.dev,
xueqin Luo <luoxueqin@...inos.cn>
Subject: [RESEND PATCH-next] staging: rtl8723bs: replace deprecated strncpy with strscpy_pad
`strncpy` is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.
We should NUL-pad as there are full struct copies happening in places:
| case NL80211_IFTYPE_MONITOR:
| ret = rtw_cfg80211_add_monitor_if(padapter,
| (char *)name, &ndev);
| break;
A suitable replacement is `strscpy_pad` due to the fact that it
guarantees both NUL-termination and NUL-padding on the destination
buffer.
Additionally, replace size macro `IFNAMSIZ` with sizeof():
| struct net_device {
| char name[IFNAMSIZ];
| ...
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Signed-off-by: xueqin Luo <luoxueqin@...inos.cn>
---
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 1ff763c10064..90d521571f0e 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -2144,8 +2144,7 @@ static int rtw_cfg80211_add_monitor_if(struct adapter *padapter, char *name, str
}
mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
- strncpy(mon_ndev->name, name, IFNAMSIZ);
- mon_ndev->name[IFNAMSIZ - 1] = 0;
+ strscpy_pad(mon_ndev->name, name, sizeof(mon_ndev->name));
mon_ndev->needs_free_netdev = true;
mon_ndev->priv_destructor = rtw_ndev_destructor;
--
2.34.1
Powered by blists - more mailing lists