* [PATCH] wireless/ti/wl1251: Replace strncpy with strscpy in fw_version
@ 2025-09-09 11:08 Rahul Kumar
0 siblings, 0 replies; only message in thread
From: Rahul Kumar @ 2025-09-09 11:08 UTC (permalink / raw)
To: linux-wireless, linux-kernel; +Cc: linux-kernel-mentees, skhan, rk0006818
strncpy is deprecated for use on NUL-terminated strings, as documented in
Documentation/process/deprecated.rst. It NUL-pads the destination buffer
and does not guarantee NUL termination if the source string is longer
than the copy length
This patch replaces the existing strncpy() and manual NUL termination with
strscpy(), which ensures safe copying and automatic NUL termination.
Signed-off-by: Rahul Kumar <rk0006818@gmail.com>
---
drivers/net/wireless/ti/wl1251/acx.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/drivers/net/wireless/ti/wl1251/acx.c b/drivers/net/wireless/ti/wl1251/acx.c
index f78fc3880423..73232f7e92d1 100644
--- a/drivers/net/wireless/ti/wl1251/acx.c
+++ b/drivers/net/wireless/ti/wl1251/acx.c
@@ -149,15 +149,8 @@ int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
goto out;
}
- /* 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';
+ /* copy firmware version safely, strscpy ensures NUL termination */
+ strscpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
out:
kfree(rev);
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-09-09 11:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-09 11:08 [PATCH] wireless/ti/wl1251: Replace strncpy with strscpy in fw_version Rahul Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox