Skip to content

Commit 91d99a7

Browse files
xywangsjtuLey Foon Tan
authored andcommitted
nios2: force the string buffer NULL-terminated
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]>
1 parent 4d856f7 commit 91d99a7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/nios2/kernel/setup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,18 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
123123
dtb_passed = r6;
124124

125125
if (r7)
126-
strncpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
126+
strlcpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
127127
}
128128
#endif
129129

130130
early_init_devtree((void *)dtb_passed);
131131

132132
#ifndef CONFIG_CMDLINE_FORCE
133133
if (cmdline_passed[0])
134-
strncpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
134+
strlcpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
135135
#ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
136136
else
137-
strncpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
137+
strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
138138
#endif
139139
#endif
140140

0 commit comments

Comments
 (0)