Skip to content

Commit

Permalink
nios2: force the string buffer NULL-terminated
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Ley Foon Tan <[email protected]>
  • Loading branch information
xywangsjtu authored and Ley Foon Tan committed Sep 20, 2019
1 parent 4d856f7 commit 91d99a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions arch/nios2/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ 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

early_init_devtree((void *)dtb_passed);

#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

Expand Down

0 comments on commit 91d99a7

Please sign in to comment.