brcmfmac: replace strncpy() by strscpy()
authorXulin Sun <xulin.sun@windriver.com>
Fri, 23 Aug 2019 07:47:08 +0000 (15:47 +0800)
committerKalle Valo <kvalo@codeaurora.org>
Tue, 3 Sep 2019 13:41:53 +0000 (16:41 +0300)
The strncpy() may truncate the copied string,
replace it by the safer strscpy().

To avoid below compile warning with gcc 8.2:

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:In function 'brcmf_vndr_ie':
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:4227:2:
warning: 'strncpy' output truncated before terminating nul copying 3 bytes from a string of the same length [-Wstringop-truncation]
  strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Xulin Sun <xulin.sun@windriver.com>
Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c

index 581d0013f33eaf17a836bcb2d0e7052da3f86c2b..5dcaaf65799e4ae4b23f14e25072f160e695a354 100644 (file)
@@ -4244,9 +4244,7 @@ next:
 static u32
 brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
 {
-
-       strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
-       iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
+       strscpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN);
 
        put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);