Commit ab41a974 authored by Will Deacon's avatar Will Deacon

arm64/sysreg: Fix broken strncpy() -> strscpy() conversion

Mostafa reports that commit d2326067 ("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: default avatarMostafa Saleh <smostafa@google.com>
Tested-by: default avatarMostafa Saleh <smostafa@google.com>
Fixes: d2326067 ("arm64/sysreg: refactor deprecated strncpy")
Signed-off-by: default avatarJustin 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.comSigned-off-by: default avatarWill Deacon <will@kernel.org>
parent 7625df9f
...@@ -262,9 +262,9 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) ...@@ -262,9 +262,9 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
if (!len) if (!len)
return; return;
len = strscpy(buf, cmdline, ARRAY_SIZE(buf)); len = min(len, ARRAY_SIZE(buf) - 1);
if (len == -E2BIG) memcpy(buf, cmdline, len);
len = ARRAY_SIZE(buf) - 1; buf[len] = '\0';
if (strcmp(buf, "--") == 0) if (strcmp(buf, "--") == 0)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment