Skip to contentSkip to conversation

sparc: kernel: using strlcpy() instead of strcpy()

PATCH Applied Zhao Hongjiang 2 participants 2 messages Jun 9, 2013 – Jun 19, 2013 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc: kernel: using strlcpy() instead of strcpy()

'boot_command_line' and 'full_boot_str' has a fix length, 'cmdline_p' and 'boot_command' maybe larger than them. So use strlcpy() instead of strcpy() to avoid memory overflow.

---
 arch/sparc/kernel/ds.c       |    3 ++-
 arch/sparc/kernel/setup_32.c |    2 +-
 arch/sparc/kernel/setup_64.c |    2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
arch/sparc/kernel/ds.c +2 -1
index 75bb608..5ef48da 100644
@@ -843,7 +843,8 @@ void ldom_reboot(const char *boot_command)
 		unsigned long len;
 
 		strcpy(full_boot_str, "boot ");
-		strcpy(full_boot_str + strlen("boot "), boot_command);
+		strlcpy(full_boot_str + strlen("boot "), boot_command,
+			sizeof(full_boot_str + strlen("boot ")));
 		len = strlen(full_boot_str);
 
 		if (reboot_data_supported) {
arch/sparc/kernel/setup_32.c +1 -1
index 38bf80a..1434526 100644
@@ -304,7 +304,7 @@ void __init setup_arch(char **cmdline_p)
 
 	/* Initialize PROM console and command line. */
 	*cmdline_p = prom_getbootargs();
-	strcpy(boot_command_line, *cmdline_p);
+	strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
 	parse_early_param();
 
 	boot_flags_init(*cmdline_p);
arch/sparc/kernel/setup_64.c +1 -1
index 88a127b..1378554 100644
@@ -555,7 +555,7 @@ void __init setup_arch(char **cmdline_p)
 {
 	/* Initialize PROM console and command line. */
 	*cmdline_p = prom_getbootargs();
-	strcpy(boot_command_line, *cmdline_p);
+	strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
 	parse_early_param();
 
 	boot_flags_init(*cmdline_p);
Signature · 1 line
1.7.1
maintainer Applied
#1 lore raw

From: Zhao Hongjiang <[email protected]>
Date: Sun, 9 Jun 2013 16:57:58 +0800

Quoted 5 lines

'boot_command_line' and 'full_boot_str' has a fix length, 'cmdline_p' and 'boot_command' maybe larger than them. So use strlcpy() instead of strcpy() to avoid memory overflow.

Applied.