Re: [PATCH v2] crypto: Replace strlcpy with strscpy
From: Herbert Xu
Date: Fri Jul 14 2023 - 04:51:44 EST
On Tue, Jun 20, 2023 at 08:08:32PM +0000, Azeem Shaikh wrote:
> strlcpy() reads the entire source buffer first.
> This read may exceed the destination size limit.
> This is both inefficient and can lead to linear read
> overflows if a source string is not NUL-terminated [1].
> In an effort to remove strlcpy() completely [2], replace
> strlcpy() here with strscpy().
>
> Direct replacement is safe here since return value of -errno
> is used to check for truncation instead of sizeof(dest).
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
> [2] https://github.com/KSPP/linux/issues/89
>
> Signed-off-by: Azeem Shaikh <azeemshaikh38@xxxxxxxxx>
> ---
> v2:
> * Use "int len" instead of "unsigned len" to hold return value of strscpy.
>
> v1:
> * https://lore.kernel.org/all/20230613002258.3535506-1-azeemshaikh38@xxxxxxxxx/
>
> crypto/lrw.c | 6 +++---
> crypto/xts.c | 6 +++---
> 2 files changed, 6 insertions(+), 6 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt