public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] wl1251: use strscpy() to instead of strncpy()
@ 2022-12-23  2:58 yang.yang29
  0 siblings, 0 replies; only message in thread
From: yang.yang29 @ 2022-12-23  2:58 UTC (permalink / raw)
  To: kvalo
  Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel, xu.panda,
	yang.yang29

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(-)

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);
-- 
2.15.2

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-23  2:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-23  2:58 [PATCH net-next] wl1251: use strscpy() to instead of strncpy() yang.yang29

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox