Skip to content

Commit ab41a97

Browse files
committed
arm64/sysreg: Fix broken strncpy() -> strscpy() conversion
Mostafa reports that commit d232606 ("arm64/sysreg: refactor deprecated strncpy") breaks our early command-line parsing because the original code is working on space-delimited substrings rather than NUL-terminated strings. Rather than simply reverting the broken conversion patch, replace the strscpy() with a simple memcpy() with an explicit NUL-termination of the result. Reported-by: Mostafa Saleh <smostafa@google.com> Tested-by: Mostafa Saleh <smostafa@google.com> Fixes: d232606 ("arm64/sysreg: refactor deprecated strncpy") Signed-off-by: Justin Stitt <justinstitt@google.com> Link: https://lore.kernel.org/r/20230905-strncpy-arch-arm64-v4-1-bc4b14ddfaef@google.com Link: https://lore.kernel.org/r/20230831162227.2307863-1-smostafa@google.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 7625df9 commit ab41a97

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/arm64/kernel/idreg-override.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
262262
if (!len)
263263
return;
264264

265-
len = strscpy(buf, cmdline, ARRAY_SIZE(buf));
266-
if (len == -E2BIG)
267-
len = ARRAY_SIZE(buf) - 1;
265+
len = min(len, ARRAY_SIZE(buf) - 1);
266+
memcpy(buf, cmdline, len);
267+
buf[len] = '\0';
268268

269269
if (strcmp(buf, "--") == 0)
270270
return;

0 commit comments

Comments
 (0)