All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/setup: Replace strlcat() with snprintf() in setup_arch()
@ 2026-06-25 15:01 Thorsten Blum
  0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-06-25 15:01 UTC (permalink / raw)
  To: Andy Shevchenko, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Andrew Morton, Ard Biesheuvel,
	Mike Rapoport (Microsoft), Thomas Zimmermann, Jiri Bohac,
	Harshit Mogalapalli
  Cc: Thorsten Blum, Ingo Molnar, linux-kernel

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.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Use a Link: tag as suggested by Andy
- v1: https://lore.kernel.org/r/20260604131752.1327556-3-thorsten.blum@linux.dev/
---
 arch/x86/kernel/setup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 46882ce79c3a..b11b0ce31a27 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -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;
 
 	/*

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-25 15:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25 15:01 [PATCH v2] x86/setup: Replace strlcat() with snprintf() in setup_arch() Thorsten Blum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.