Skip to contentSkip to conversation

m68k: mm: Replace deprecated strncpy() with strscpy()

PATCH In review Thorsten Blum 5 participants 5 messages Feb 13, 2025 – Feb 20, 2025 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 m68k: mm: Replace deprecated strncpy() with strscpy()

strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

---
 arch/m68k/kernel/setup_mm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/m68k/kernel/setup_mm.c +1 -2
index 15c1a595a1de..48ce67947678 100644
@@ -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.48.1
Tested-by on v1 1/1
#1 lore raw

Hi Thorsten,

Quoted 8 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

Thanks for the patch !
It works fine for me:

Quoted 18 lines
---
  arch/m68k/kernel/setup_mm.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
arch/m68k/kernel/setup_mm.c +1 -2
index 15c1a595a1de..48ce67947678 100644
@@ -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;
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Thorsten Blum
Quoted 8 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

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;

This seems to be used mostly by Coldfire, so I'll let Greg handle it.

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
#3 lore raw

Hi Thorsten,

Quoted 17 lines · Geert Uytterhoeven
Quoted 8 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

Quoted 5 lines
arch/m68k/kernel/setup_mm.c +0 -0
@@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)
         setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
 
Quoted 9 lines

arch/m68k/kernel/setup_mm.c void __init setup_arch(char **cmdline_p) · line 249

Quoted 7 lines
arch/m68k/kernel/setup_mm.c +1 -2
  #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;

This seems to be used mostly by Coldfire, so I'll let Greg handle it.

Looks good. Pushed into the m68knommu git tree, for-next branch, with JM's tested-by and Geert's reviewed-by added.

Thanks
Greg

Reviewed-by on v1 1/1
#4 lore raw
In reply to Thorsten Blum
Quoted 17 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

---
 arch/m68k/kernel/setup_mm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/m68k/kernel/setup_mm.c +0 -0
index 15c1a595a1de..48ce67947678 100644

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;

m68k_command_line lives in rwdata, so it should be 0-initialized by default, so there should be no behavioral difference here (i.e. it will be zero-padded), and it is used as a C String, so there was unlikely to be anything depending on the NUL-padding.

Signature · 1 line
Kees Cook