Re: [PATCH linux-next] arm64/idreg: use strscpy() is more robust and safer

From: Will Deacon
Date: Tue Oct 04 2022 - 07:48:43 EST


On Thu, Sep 29, 2022 at 07:29:06AM +0000, xu.panda668@xxxxxxxxx wrote:
> From: Xu Panda <xu.panda@xxxxxxxxxx>
>
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
>
> Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
> Signed-off-by: Xu Panda <xu.panda@xxxxxxxxxx>
> Signed-off-by: Xu Panda <xu.panda668@xxxxxxxxx>
> ---
> arch/arm64/kernel/idreg-override.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c
> index 95133765ed29..61bbec7ef62e 100644
> --- a/arch/arm64/kernel/idreg-override.c
> +++ b/arch/arm64/kernel/idreg-override.c
> @@ -246,7 +246,7 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
> return;
>
> len = min(len, ARRAY_SIZE(buf) - 1);
> - strncpy(buf, cmdline, len);
> + strscpy(buf, cmdline, len);
> buf[len] = 0;

Aren't we terminating the buffer explicitly here anyway?

Will