Skip to content

Commit 9ddef26

Browse files
Jason Wangjcmvbkbc
authored andcommitted
xtensa: use strscpy to copy strings
The strlcpy should not be used because it doesn't limit the source length. So that it 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, replace strlcpy with strscpy. Signed-off-by: Jason Wang <wangborong@cdjrlc.com> Message-Id: <20211220084756.955307-1-wangborong@cdjrlc.com> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
1 parent b8f9a9a commit 9ddef26

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

arch/xtensa/kernel/setup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ __tagtable(BP_TAG_FDT, parse_tag_fdt);
140140

141141
static int __init parse_tag_cmdline(const bp_tag_t* tag)
142142
{
143-
strlcpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE);
143+
strscpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE);
144144
return 0;
145145
}
146146

@@ -230,7 +230,7 @@ void __init early_init_devtree(void *params)
230230
of_scan_flat_dt(xtensa_dt_io_area, NULL);
231231

232232
if (!command_line[0])
233-
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
233+
strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
234234
}
235235

236236
#endif /* CONFIG_USE_OF */
@@ -260,7 +260,7 @@ void __init init_arch(bp_tag_t *bp_start)
260260

261261
#ifdef CONFIG_CMDLINE_BOOL
262262
if (!command_line[0])
263-
strlcpy(command_line, default_command_line, COMMAND_LINE_SIZE);
263+
strscpy(command_line, default_command_line, COMMAND_LINE_SIZE);
264264
#endif
265265

266266
/* Early hook for platforms */
@@ -289,7 +289,7 @@ void __init setup_arch(char **cmdline_p)
289289

290290
*cmdline_p = command_line;
291291
platform_setup(cmdline_p);
292-
strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
292+
strscpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
293293

294294
/* Reserve some memory regions */
295295

0 commit comments

Comments
 (0)