linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] riscv: use strscpy to replace strlcpy
       [not found] <20210807071427.59613-1-wangborong@cdjrlc.com>
@ 2021-08-26  6:08 ` Palmer Dabbelt
  0 siblings, 0 replies; only message in thread
From: Palmer Dabbelt @ 2021-08-26  6:08 UTC (permalink / raw)
  To: wangborong
  Cc: Paul Walmsley, aou, Atish Patra, Anup Patel, wangkefeng.wang,
	mick, alex, linux-riscv, linux-kernel, wangborong

On Sat, 07 Aug 2021 00:14:27 PDT (-0700), wangborong@cdjrlc.com wrote:
> The strlcpy should not be used because it doesn't limit the source
> length. As linus says, it's a completely useless function if you
> can't implicitly trust the source string - but that is almost always
> why people think they should use it! All in all the BSD function
> will lead some potential bugs.
>
> But the strscpy doesn't require reading memory from the src string
> beyond the specified "count" bytes, and since the return value is
> easier to error-check than strlcpy()'s. In addition, the implementation
> is robust to the string changing out from underneath it, unlike the
> current strlcpy() implementation.
>
> Thus, We prefer using strscpy instead of strlcpy.
>
> Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
> ---
>  arch/riscv/kernel/setup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 18bd0e4bc36c..2dc62ebc0001 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -255,7 +255,7 @@ static void __init parse_dtb(void)
>
>  	pr_err("No DTB passed to the kernel\n");
>  #ifdef CONFIG_CMDLINE_FORCE
> -	strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> +	strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
>  	pr_info("Forcing kernel command line to: %s\n", boot_command_line);
>  #endif
>  }

Thanks, this is on for-next.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-26  6:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210807071427.59613-1-wangborong@cdjrlc.com>
2021-08-26  6:08 ` [PATCH] riscv: use strscpy to replace strlcpy Palmer Dabbelt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).