Messages in this thread | | | Date | Mon, 9 Oct 2023 12:58:32 -0700 | From | Kees Cook <> | Subject | Re: [PATCH v2] bna: replace deprecated strncpy with strscpy_pad |
| |
On Mon, Oct 09, 2023 at 05:45:33PM +0000, Justin Stitt wrote: > `strncpy` is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > bfa_ioc_get_adapter_manufacturer() simply copies a string literal into > `manufacturer`. > > Another implementation of bfa_ioc_get_adapter_manufacturer() from > drivers/scsi/bfa/bfa_ioc.c uses memset + strscpy: > | void > | bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer) > | { > | memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN); > | strscpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); > | } > > Let's use `strscpy_pad` to eliminate some redundant work while still > NUL-terminating and NUL-padding the destination buffer. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt <justinstitt@google.com>
Thanks for the update! Yeah, this looks safe to me now.
Reviewed-by: Kees Cook <keescook@chromium.org>
-- Kees Cook
| |