Skip to contentSkip to conversation

m68k: Replace memcpy() + manual NUL-termination with strscpy()

PATCH Applied Thorsten Blum 2 participants 2 messages Apr 15, 2025 – Apr 27, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 m68k: Replace memcpy() + manual NUL-termination with strscpy()

Use strscpy() to safely copy the command-line string instead of memcpy() followed by a manual NUL-termination.

The source string is also NUL-terminated and meets the __must_be_cstr() requirement of strscpy().

No functional changes intended.

---
 arch/m68k/kernel/setup_no.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/m68k/kernel/setup_no.c +1 -2
index f9872098f5ca..f724875b15cc 100644
@@ -145,8 +145,7 @@ void __init setup_arch(char **cmdline_p)
 
 	/* Keep a copy of command line */
 	*cmdline_p = &command_line[0];
-	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
-	boot_command_line[COMMAND_LINE_SIZE-1] = 0;
+	strscpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
 
 	/*
 	 * Give all the memory to the bootmap allocator, tell it to put the
Signature · 1 line
2.49.0
maintainer Applied
#1 lore raw

Hi Thorsten,

Quoted 9 lines · Thorsten Blum

Use strscpy() to safely copy the command-line string instead of memcpy() followed by a manual NUL-termination.

The source string is also NUL-terminated and meets the __must_be_cstr() requirement of strscpy().

No functional changes intended.

Thanks, applied to m68knommu git tree, for-next branch.

Regards
Greg

Quoted 18 lines
---
  arch/m68k/kernel/setup_no.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
arch/m68k/kernel/setup_no.c +1 -2
index f9872098f5ca..f724875b15cc 100644
@@ -145,8 +145,7 @@ void __init setup_arch(char **cmdline_p)
 
  	/* Keep a copy of command line */
  	*cmdline_p = &command_line[0];
-	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
-	boot_command_line[COMMAND_LINE_SIZE-1] = 0;
+	strscpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
 
  	/*
  	 * Give all the memory to the bootmap allocator, tell it to put the