[RESEND PATCH-next] staging: rtl8723bs: replace deprecated strncpy with strscpy_pad

From: xueqin Luo
Date: Tue Dec 12 2023 - 20:19:23 EST


`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@xxxxxxxxxx>
---
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