wifi: ath5k: replace deprecated strncpy with strscpy
authorJustin Stitt <justinstitt@google.com>
Fri, 13 Oct 2023 20:53:33 +0000 (20:53 +0000)
committerKalle Valo <quic_kvalo@quicinc.com>
Wed, 18 Oct 2023 08:31:36 +0000 (11:31 +0300)
commit24709752bfe8bc0147c9379a6ec8fe8d75874066
treea314d9368f2a0894734684d92a5d0b15414770dd
parent2180f7ac0abeee63cc608b1c084764b67832596c
wifi: ath5k: replace deprecated strncpy with strscpy

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 expect led->name to be NUL-terminated based on the presence of a
manual NUL-byte assignment.

This NUL-byte assignment was added in Commit daf9669bea30aa22 ("ath5k:
ensure led name is null terminated"). If strscpy() had existed and had
been used back when this code was written then potential bugs and the
need to manually NUL-terminate could have been avoided. Since we now
have the technology, let's use it :)

Considering the above, a suitable replacement is `strscpy` [2] due to
the fact that it guarantees NUL-termination on the destination buffer
without unnecessarily NUL-padding. If NUL-padding is required let's opt
for strscpy_pad().

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
Link: https://lore.kernel.org/r/20231013-strncpy-drivers-net-wireless-ath-ath5k-led-c-v1-1-3acb0b5a21f2@google.com
drivers/net/wireless/ath/ath5k/led.c