[net-next] wl1251: use strscpy() to instead of strncpy()

Message ID 202212231058555242869@zte.com.cn
State New
Headers
Series [net-next] wl1251: use strscpy() to instead of strncpy() |

Commit Message

Yang Yang Dec. 23, 2022, 2:58 a.m. UTC
  From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL-terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
 drivers/net/wireless/ti/wl1251/acx.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
  

Patch

diff --git a/drivers/net/wireless/ti/wl1251/acx.c b/drivers/net/wireless/ti/wl1251/acx.c
index f78fc3880423..613ddab068c3 100644
--- a/drivers/net/wireless/ti/wl1251/acx.c
+++ b/drivers/net/wireless/ti/wl1251/acx.c
@@ -150,14 +150,7 @@  int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
 	}

 	/* be careful with the buffer sizes */
-	strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
-
-	/*
-	 * if the firmware version string is exactly
-	 * sizeof(rev->fw_version) long or fw_len is less than
-	 * sizeof(rev->fw_version) it won't be null terminated
-	 */
-	buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
+	strscpy(buf, rev->fw_version, len);

 out:
 	kfree(rev);