Re: [PATCH v2] scsi: elx: sli4: Replace deprecated strncpy() with strscpy()
From: Kees Cook
Date: Tue Apr 08 2025 - 19:43:00 EST
On Tue, Apr 08, 2025 at 12:28:40PM +0200, Thorsten Blum wrote:
> strncpy() is deprecated for NUL-terminated destination buffers; use
> strscpy() instead.
>
> Since sli_config_cmd_init() already zeroes out the destination buffers,
> the potential NUL-padding by strncpy() is unnecessary. strscpy() copies
> only the required characters and guarantees NUL-termination.
>
> And since all three destination buffers have a fixed length, strscpy()
> automatically determines their size using sizeof() when the argument is
> omitted. This makes any explicit sizeof() calls unnecessary.
>
> The source strings are also NUL-terminated and meet the __must_be_cstr()
> requirement of strscpy().
>
> No functional changes intended.
>
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@xxxxxxxxxxxxxxx
> Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
Reviewed-by: Kees Cook <kees@xxxxxxxxxx>
--
Kees Cook