Skip to contentSkip to conversation

x86/setup: use strscpy to replace strlcpy

PATCH Applied XueBing Chen 2 participants 2 messages May 25, 2022 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/setup: use strscpy to replace strlcpy

The strlcpy should not be used because it doesn't limit the source length. Preferred is strscpy.

---
 arch/x86/kernel/setup.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/setup.c +3 -3
index c95b9ac5a457..f95eaba2c8ad 100644
@@ -879,18 +879,18 @@ void __init setup_arch(char **cmdline_p)
 
 #ifdef CONFIG_CMDLINE_BOOL
 #ifdef CONFIG_CMDLINE_OVERRIDE
-	strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+	strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
 #else
 	if (builtin_cmdline[0]) {
 		/* append boot loader cmdline to builtin */
 		strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
 		strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-		strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+		strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
 	}
 #endif
 #endif
 
-	strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+	strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
 	*cmdline_p = command_line;
 
 	/*
Signature · 1 line
2.36.1
merge bot Applied
#1 lore raw

[tip: x86/boot] x86/setup: Use strscpy() to replace deprecated strlcpy()

The following commit has been merged into the x86/boot branch of tip:

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     8a33d96bd178d5f49cc5c1898e4cda08e221d2db
Gitweb:        https://git.kernel.org/tip/8a33d96bd178d5f49cc5c1898e4cda08e221d2db
Author:        XueBing Chen <[email protected]>
AuthorDate:    Wed, 25 May 2022 16:51:01 +08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Wed, 25 May 2022 15:34:38 +02:00

x86/setup: Use strscpy() to replace deprecated strlcpy()

strlcpy() is marked deprecated and should not be used, because it doesn't limit the source length.

The preferred interface for when strlcpy()'s return value is not checked (truncation) is strscpy().

[ mingo: Tweaked the changelog ]

---
 arch/x86/kernel/setup.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/setup.c +3 -3
index 249981b..3ebb853 100644
@@ -903,18 +903,18 @@ void __init setup_arch(char **cmdline_p)
 
 #ifdef CONFIG_CMDLINE_BOOL
 #ifdef CONFIG_CMDLINE_OVERRIDE
-	strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+	strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
 #else
 	if (builtin_cmdline[0]) {
 		/* append boot loader cmdline to builtin */
 		strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
 		strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-		strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+		strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
 	}
 #endif
 #endif
 
-	strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+	strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
 	*cmdline_p = command_line;
 
 	/*