Re: [PATCH] nios2: force the string buffer NULL-terminated

From: Ley Foon Tan
Date: Tue Oct 01 2019 - 20:52:55 EST


On Mon, 2019-08-05 at 18:17 +0800, Wang Xiayang wrote:
> strncpy() does not ensure NULL-termination when the input string
> size equals to the destination buffer size COMMAND_LINE_SIZE.
> Besides, grep under arch/ with 'boot_command_line' shows
> no other arch-specific code uses strncpy() when copying
> boot_command_line.
>
> Use strlcpy() instead.
>
> This issue is identified by a Coccinelle script.
>
> Signed-off-by: Wang Xiayang <xywang.sjtu@xxxxxxxxxxx>
Merged to v5.4-rc1. Thanks.


Acked-by: Ley Foon Tan <ley.foon.tan@xxxxxxxxx>


> ---
> Âarch/nios2/kernel/setup.c | 6 +++---
> Â1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c
> index 6bbd4ae2beb0..4cf35b09c0ec 100644
> --- a/arch/nios2/kernel/setup.c
> +++ b/arch/nios2/kernel/setup.c
> @@ -123,7 +123,7 @@ asmlinkage void __init nios2_boot_init(unsigned
> r4, unsigned r5, unsigned r6,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂdtb_passed = r6;
>
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂif (r7)
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstrncpy(cmdline_passed, (char *)r7,
> COMMAND_LINE_SIZE);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstrlcpy(cmdline_passed, (char *)r7,
> COMMAND_LINE_SIZE);
> ÂÂÂÂÂÂÂÂ}
> Â#endif
>
> @@ -131,10 +131,10 @@ asmlinkage void __init nios2_boot_init(unsigned
> r4, unsigned r5, unsigned r6,
>
> Â#ifndef CONFIG_CMDLINE_FORCE
> ÂÂÂÂÂÂÂÂif (cmdline_passed[0])
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstrncpy(boot_command_line, cmdline_passed,
> COMMAND_LINE_SIZE);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstrlcpy(boot_command_line, cmdline_passed,
> COMMAND_LINE_SIZE);
> Â#ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
> ÂÂÂÂÂÂÂÂelse
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstrncpy(boot_command_line, CONFIG_CMDLINE,
> COMMAND_LINE_SIZE);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstrlcpy(boot_command_line, CONFIG_CMDLINE,
> COMMAND_LINE_SIZE);
> Â#endif
> Â#endif
>
> --
> 2.11.0
>
>
> ________________________________
>
> Confidentiality Notice.
> This message may contain information that is confidential or
> otherwise protected from disclosure. If you are not the intended
> recipient, you are hereby notified that any use, disclosure,
> dissemination, distribution, or copying of this message, or any
> attachments, is strictly prohibited. If you have received this
> message in error, please advise the sender by reply e-mail, and
> delete the message and any attachments. Thank you.