Skip to content

Commit 803930e

Browse files
Jason Wangpalmer-dabbelt
authored andcommitted
riscv: use strscpy to replace strlcpy
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 <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent fde9c59 commit 803930e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/riscv/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static void __init parse_dtb(void)
255255

256256
pr_err("No DTB passed to the kernel\n");
257257
#ifdef CONFIG_CMDLINE_FORCE
258-
strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
258+
strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
259259
pr_info("Forcing kernel command line to: %s\n", boot_command_line);
260260
#endif
261261
}

0 commit comments

Comments
 (0)