Skip to contentSkip to conversation

x86/setup: Replace strlcat() with snprintf() in setup_arch()

PATCH RESEND New Thorsten Blum 1 participant 1 message Jul 27 x86

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 x86/setup: Replace strlcat() with snprintf() in setup_arch()

In preparation to remove strlcat() from the kernel [1], replace two strlcat() calls with snprintf() in setup_arch().

Also drop the explicit size argument to strscpy() to further simplify the code since strscpy() can determine the size automatically when the destination buffer has a fixed length.

---
Changes in v2:
- Use a Link: tag as suggested by Andy
- v1: https://lore.kernel.org/r/[email protected]/

---
 arch/x86/kernel/setup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/setup.c +6 -3
index 46882ce79c3a..b11b0ce31a27 100644
@@ -21,6 +21,7 @@
 #include <linux/pci.h>
 #include <linux/random.h>
 #include <linux/root_dev.h>
+#include <linux/sprintf.h>
 #include <linux/static_call.h>
 #include <linux/sysfb.h>
 #include <linux/swiotlb.h>
@@ -915,16 +916,18 @@ void __init setup_arch(char **cmdline_p)
 	strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
 #else
 	if (builtin_cmdline[0]) {
+		size_t len = strnlen(builtin_cmdline, COMMAND_LINE_SIZE);
+
 		/* append boot loader cmdline to builtin */
-		strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-		strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
+		snprintf(builtin_cmdline + len, COMMAND_LINE_SIZE - len, " %s",
+			 boot_command_line);
 		strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
 	}
 #endif
 	builtin_cmdline_added = true;
 #endif
 
-	strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+	strscpy(command_line, boot_command_line);
 	*cmdline_p = command_line;
 
 	/*