lkml.org 
[lkml]   [2022]   [Dec]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH linux-next] accessibility: speakup: use strscpy() to instead of strncpy()
yang.yang29@zte.com.cn, le sam. 03 déc. 2022 14:21:28 +0800, a ecrit:
> 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>
> ---
> drivers/accessibility/speakup/kobjects.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/accessibility/speakup/kobjects.c b/drivers/accessibility/speakup/kobjects.c
> index a7522d409802..273c076b661a 100644
> --- a/drivers/accessibility/speakup/kobjects.c
> +++ b/drivers/accessibility/speakup/kobjects.c
> @@ -426,8 +426,7 @@ static ssize_t synth_direct_store(struct kobject *kobj,
> spin_lock_irqsave(&speakup_info.spinlock, flags);
> while (len > 0) {
> bytes = min_t(size_t, len, 250);
> - strncpy(tmp, ptr, bytes);
> - tmp[bytes] = '\0';
> + strscpy(tmp, ptr, bytes);

This needs to be bytes+1, otherwise the trailing `\0` will be put at
bytes-1 instead of bytes as the original code does, thus eating one
character.

> string_unescape_any_inplace(tmp);
> synth_printf("%s", tmp);
> ptr += bytes;
> --
> 2.15.2
>

\
 
 \ /
  Last update: 2022-12-03 10:57    [W:0.032 / U:4.744 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site