Skip to contentSkip to conversation

printk: use strscpy() to instead of strlcpy()

PATCH In review [email protected] 3 participants 4 messages Nov 30, 2022 Printk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 printk: use strscpy() to instead of strlcpy()

From: Xu Panda <[email protected]>

The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings.

---
 kernel/printk/printk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/printk/printk.c +1 -1
index 9ec101766471..7decf1e9c486 100644
@@ -2480,7 +2480,7 @@ static int __add_preferred_console(char *name, int idx, char *options,
 		return -E2BIG;
 	if (!brl_options)
 		preferred_console = i;
-	strlcpy(c->name, name, sizeof(c->name));
+	strscpy(c->name, name, sizeof(c->name));
 	c->options = options;
 	set_user_specified(c, user_specified);
 	braille_set_options(c, brl_options);
Signature · 1 line
2.15.2
maintainer
#1 lore raw
Quoted 7 lines · On 2022-11-30, <[email protected]> wrote:

From: Xu Panda <[email protected]>

The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings.

This looks fine, but I am wondering if we should also replace all strncpy() usage as well. AFAICT they can all be replaced. It would also avoid the manual termination in console_setup().

John Ogness

maintainer
#2 lore raw
Quoted 6 lines · John Ogness
Quoted 5 lines · On 2022-11-30, <[email protected]> wrote:

From: Xu Panda <[email protected]>

The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings.

Quoted 6 lines
Quoted 2 lines

This looks fine, but I am wondering if we should also replace all strncpy() usage as well. AFAICT they can all be replaced. It would also avoid the manual termination in console_setup().

I agree that it would be nice to replace strncpy() as well. But it might be done in a separate patch.

Yang, Xu, would you like to do it, please?

Best Regards,
Petr