Skip to contentSkip to conversation

m68k/kernel: replace strncpy() with strscpy()

PATCH In review Mohammad Mahdi Anbaraki 2 participants 3 messages Apr 3, 2025 – Apr 27, 2025 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 m68k/kernel: replace strncpy() with strscpy()

Swapped out strncpy() for strscpy() in parse_uboot_commandline() while copying to commandp. strscpy() makes sure the string is properly null- terminated and gives a more useful return value so it's just a safer choice overall.

---
Changes in v2:
- s/m64/m68

 arch/m68k/kernel/uboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/m68k/kernel/uboot.c +1 -1
index 5e52ea150..fa7c279ea 100644
@@ -73,7 +73,7 @@ static void __init parse_uboot_commandline(char *commandp, int size)
 	uboot_cmd_end = sp[5];
 
 	if (uboot_cmd_start && uboot_cmd_end)
-		strncpy(commandp, (const char *)uboot_cmd_start, size);
+		strscpy(commandp, (const char *)uboot_cmd_start, size);
 
 #if defined(CONFIG_BLK_DEV_INITRD)
 	uboot_initrd_start = sp[2];
Signature · 1 line
2.43.0
#1 lore raw

Hi
.Just a gentle follow-up on this patch
/s/m64k/m68k

‫‪Mohammad Mahdi Anbaraki‬‏ <‪[email protected]‬‏> در تاریخ پنجشنبه ۳ آوریل ۲۰۲۵ ساعت ۲۱:۴۲ نوشت:‬

Quoted 31 lines

Swapped out strncpy() for strscpy() in parse_uboot_commandline() while copying to commandp. strscpy() makes sure the string is properly null- terminated and gives a more useful return value so it's just a safer choice overall.

---
Changes in v2:
- s/m64/m68

 arch/m68k/kernel/uboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/m68k/kernel/uboot.c +1 -2
index 5e52ea150..fa7c279ea 100644
@@ -73,7 +73,7 @@ static void __init parse_uboot_commandline(char *commandp, int size)
        uboot_cmd_end = sp[5];
 
        if (uboot_cmd_start && uboot_cmd_end)
-               strncpy(commandp, (const char *)uboot_cmd_start, size);
+               strscpy(commandp, (const char *)uboot_cmd_start, size);
 
 #if defined(CONFIG_BLK_DEV_INITRD)
        uboot_initrd_start = sp[2];
--

2.43.0

#2 lore raw
In reply to Mohammad Mahdi Anbaraki

Hi Homammad,

Quoted 7 lines · Mohammad Mahdi Anbaraki

Swapped out strncpy() for strscpy() in parse_uboot_commandline() while copying to commandp. strscpy() makes sure the string is properly null- terminated and gives a more useful return value so it's just a safer choice overall.

Thanks. Seeing as this only affects nommu/coldfire I will apply this to the m68knommu git tree, for-next branch.

Regards
Greg

Quoted 20 lines

---
Changes in v2:
- s/m64/m68

  arch/m68k/kernel/uboot.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/m68k/kernel/uboot.c +1 -1
index 5e52ea150..fa7c279ea 100644
@@ -73,7 +73,7 @@ static void __init parse_uboot_commandline(char *commandp, int size)
  	uboot_cmd_end = sp[5];
 
  	if (uboot_cmd_start && uboot_cmd_end)
-		strncpy(commandp, (const char *)uboot_cmd_start, size);
+		strscpy(commandp, (const char *)uboot_cmd_start, size);
 
  #if defined(CONFIG_BLK_DEV_INITRD)
  	uboot_initrd_start = sp[2];