* [PATCH linux-next] printk: use strscpy() to instead of strlcpy()
@ 2022-11-30 8:01 yang.yang29
2022-11-30 9:11 ` John Ogness
2022-11-30 10:39 ` Petr Mladek
0 siblings, 2 replies; 4+ messages in thread
From: yang.yang29 @ 2022-11-30 8:01 UTC (permalink / raw)
To: pmladek
Cc: senozhatsky, rostedt, john.ogness, linux-kernel, xu.panda,
yang.yang29
From: Xu Panda <xu.panda@zte.com.cn>
The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL terminated strings.
Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
kernel/printk/printk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9ec101766471..7decf1e9c486 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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);
--
2.15.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] printk: use strscpy() to instead of strlcpy()
2022-11-30 8:01 [PATCH linux-next] printk: use strscpy() to instead of strlcpy() yang.yang29
@ 2022-11-30 9:11 ` John Ogness
2022-11-30 10:43 ` Petr Mladek
2022-11-30 10:39 ` Petr Mladek
1 sibling, 1 reply; 4+ messages in thread
From: John Ogness @ 2022-11-30 9:11 UTC (permalink / raw)
To: yang.yang29, pmladek
Cc: senozhatsky, rostedt, linux-kernel, xu.panda, yang.yang29
On 2022-11-30, <yang.yang29@zte.com.cn> wrote:
> From: Xu Panda <xu.panda@zte.com.cn>
>
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
>
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] printk: use strscpy() to instead of strlcpy()
2022-11-30 8:01 [PATCH linux-next] printk: use strscpy() to instead of strlcpy() yang.yang29
2022-11-30 9:11 ` John Ogness
@ 2022-11-30 10:39 ` Petr Mladek
1 sibling, 0 replies; 4+ messages in thread
From: Petr Mladek @ 2022-11-30 10:39 UTC (permalink / raw)
To: yang.yang29; +Cc: senozhatsky, rostedt, john.ogness, linux-kernel, xu.panda
On Wed 2022-11-30 16:01:41, yang.yang29@zte.com.cn wrote:
> From: Xu Panda <xu.panda@zte.com.cn>
>
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
>
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] printk: use strscpy() to instead of strlcpy()
2022-11-30 9:11 ` John Ogness
@ 2022-11-30 10:43 ` Petr Mladek
0 siblings, 0 replies; 4+ messages in thread
From: Petr Mladek @ 2022-11-30 10:43 UTC (permalink / raw)
To: John Ogness; +Cc: yang.yang29, senozhatsky, rostedt, linux-kernel, xu.panda
On Wed 2022-11-30 10:17:07, John Ogness wrote:
> On 2022-11-30, <yang.yang29@zte.com.cn> wrote:
> > From: Xu Panda <xu.panda@zte.com.cn>
> >
> > The implementation of strscpy() is more robust and safer.
> > That's now the recommended way to copy NUL terminated strings.
> >
> > Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> > Signed-off-by: Yang Yang <yang.yang29@zte.com>
>
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-30 10:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-30 8:01 [PATCH linux-next] printk: use strscpy() to instead of strlcpy() yang.yang29
2022-11-30 9:11 ` John Ogness
2022-11-30 10:43 ` Petr Mladek
2022-11-30 10:39 ` Petr Mladek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox