m68k: replace deprecated strncpy with strscpy
PATCH 1/1 m68k: replace deprecated strncpy with strscpy
The use of strncpy() does not guarantee NUL-termination and is deprecated in the Linux kernel. This code manually terminates the buffer afterward, but using strscpy() is simpler and safer.
This change replaces the strncpy() + NUL termination pattern with strscpy().
--- arch/m68k/kernel/setup_mm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/m68k/kernel/setup_mm.c +1 -2
@@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)setup_initial_init_mm ((void *)PAGE_OFFSET , _etext, _edata, _end);#if defined(CONFIG_BOOTPARAM ) -strncpy (m68k_command_line,CONFIG_BOOTPARAM_STRING ,CL_SIZE ); - m68k_command_line[CL_SIZE -1 ] =0 ; +strscpy (m68k_command_line,CONFIG_BOOTPARAM_STRING ,CL_SIZE );#endif /* CONFIG_BOOTPARAM */ process_uboot_commandline (&m68k_command_line[0 ],CL_SIZE ); *cmdline_p = m68k_command_line;
Signature · 1 line
2.34.1
Hi Shankari,
Quoted 3 lines · On 17/04/2025 22:10, Shankari02 wrote:
The use of
strncpy()does not guarantee NUL-termination and is deprecated in the Linux kernel. This code manually terminates the buffer afterward, but usingstrscpy()is simpler and safer.
This assumption is true, but adding a link to the explanation could be better ?
https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Quoted 13 lines
This change replaces the
strncpy()+ NUL termination pattern withstrscpy().Signed-off-by Shankari Anand <[email protected]>--- arch/m68k/kernel/setup_mm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)arch/m68k/kernel/setup_mm.c +0
-0
arch/m68k/kernel/setup_mm.c void __init setup_arch(char **cmdline_p) · line 249
Quoted 9 lines
arch/m68k/kernel/setup_mm.c +1
-2@@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)setup_initial_init_mm ((void *)PAGE_OFFSET , _etext, _edata, _end);#if defined(CONFIG_BOOTPARAM ) -strncpy (m68k_command_line,CONFIG_BOOTPARAM_STRING ,CL_SIZE ); - m68k_command_line[CL_SIZE -1 ] =0 ; +strscpy (m68k_command_line,CONFIG_BOOTPARAM_STRING ,CL_SIZE );#endif /* CONFIG_BOOTPARAM */ process_uboot_commandline (&m68k_command_line[0 ],CL_SIZE ); *cmdline_p = m68k_command_line;
As we are not using the return value, I think it is a safe replacement.
With the link added:
Hi,
Quoted 34 lines · Jean-Michel Hautbois
Hi Shankari,
Quoted 3 lines · On 17/04/2025 22:10, Shankari02 wrote:
The use of
strncpy()does not guarantee NUL-termination and is deprecated in the Linux kernel. This code manually terminates the buffer afterward, but usingstrscpy()is simpler and safer.This assumption is true, but adding a link to the explanation could be better ?
https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpyQuoted 13 lines
This change replaces the
strncpy()+ NUL termination pattern withstrscpy().Signed-off-by Shankari Anand <[email protected]>---
arch/m68k/kernel/setup_mm.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)arch/m68k/kernel/setup_mm.c +0
-0arch/m68k/kernel/setup_mm.c void __init setup_arch(char **cmdline_p) · line 248
Quoted 8 lines
arch/m68k/kernel/setup_mm.c +1
-2@@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p) setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end); #if defined(CONFIG_BOOTPARAM) - strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE); - m68k_command_line[CL_SIZE - 1] = 0; + strscpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE); #endif /* CONFIG_BOOTPARAM */ process_uboot_commandline(&m68k_command_line[0], CL_SIZE); *cmdline_p = m68k_command_line;As we are not using the return value, I think it is a safe replacement.
Quoted 2 lines
With the link added:
Signed-off-by Jean-Michel Hautbois <[email protected]>
Sorry for this one:
s/Signed-off-by/Reviewed-by/
JM
Geert Uytterhoeven
maintainerHi Shankari,
Quoted 7 lines · On Thu, 17 Apr 2025 at 22:10, Shankari02 <[email protected]> wrote:
The use of
strncpy()does not guarantee NUL-termination and is deprecated in the Linux kernel. This code manually terminates the buffer afterward, but usingstrscpy()is simpler and safer.This change replaces the
strncpy()+ NUL termination pattern withstrscpy().Signed-off-by Shankari Anand <[email protected]>
Thanks for your patch!
arch/m68k/kernel/setup_mm.c void __init setup_arch(char **cmdline_p) · line 249
Quoted 12 lines
arch/m68k/kernel/setup_mm.c +1
-2@@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)setup_initial_init_mm ((void *)PAGE_OFFSET , _etext, _edata, _end);#if defined(CONFIG_BOOTPARAM ) -strncpy (m68k_command_line,CONFIG_BOOTPARAM_STRING ,CL_SIZE ); - m68k_command_line[CL_SIZE -1 ] =0 ; +strscpy (m68k_command_line,CONFIG_BOOTPARAM_STRING ,CL_SIZE );#endif /* CONFIG_BOOTPARAM */ process_uboot_commandline (&m68k_command_line[0 ],CL_SIZE ); *cmdline_p = m68k_command_line;
The same change was already applied as commit a7130910b80753d5 ("m68k:
mm: Replace deprecated strncpy() with strscpy()") in v6.15-rc1.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
A message that is not in the archive (sent off-list or not yet received): CAPRMd3m2UmfPrzD2eXW9s_Uc1kM4cwCB4pMAbSSPX+MB85=H=A@mail.gmail.com
Hi Geert,
Thank you for the quick review and for pointing that out!
Apologies for the duplicate. I'll make sure to check for existing commits more carefully next time. I appreciate your time and feedback.
Regards,
Shankari
Quoted 52 lines · Shankari
Hi Geert,
Thank you for the quick review and for pointing that out!
Apologies for the duplicate. I'll make sure to check for existing commits more carefully next time. I appreciate your time and feedback.
Regards,
ShankariQuoted 40 lines · Geert Uytterhoeven
Hi Shankari,
Quoted 7 lines · On Thu, 17 Apr 2025 at 22:10, Shankari02 <[email protected]> wrote:
The use of
strncpy()does not guarantee NUL-termination and is deprecated in the Linux kernel. This code manually terminates the buffer afterward, but usingstrscpy()is simpler and safer.This change replaces the
strncpy()+ NUL termination pattern withstrscpy().Signed-off-by Shankari Anand <[email protected]>Thanks for your patch!
arch/m68k/kernel/setup_mm.c void __init setup_arch(char **cmdline_p) · line 249
Quoted 12 lines
arch/m68k/kernel/setup_mm.c +1
-2@@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)setup_initial_init_mm ((void *)PAGE_OFFSET , _etext, _edata, _end);#if defined(CONFIG_BOOTPARAM ) -strncpy (m68k_command_line,CONFIG_BOOTPARAM_STRING ,CL_SIZE ); - m68k_command_line[CL_SIZE -1 ] =0 ; +strscpy (m68k_command_line,CONFIG_BOOTPARAM_STRING ,CL_SIZE );#endif /* CONFIG_BOOTPARAM */ process_uboot_commandline (&m68k_command_line[0 ],CL_SIZE ); *cmdline_p = m68k_command_line;The same change was already applied as commit
a7130910b80753d5("m68k:
mm: Replace deprecatedstrncpy()withstrscpy()") in v6.15-rc1.Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds