2021-02-22 05:13:00

by Zhiyuan Dai

[permalink] [raw]
Subject: [PATCH] mm/kasan: switch from strlcpy to strscpy

strlcpy is marked as deprecated in Documentation/process/deprecated.rst,
and there is no functional difference when the caller expects truncation
(when not checking the return value). strscpy is relatively better as it
also avoids scanning the whole source string.

Signed-off-by: Zhiyuan Dai <[email protected]>
---
mm/kasan/report_generic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c
index 8a9c889..fc7f7ad 100644
--- a/mm/kasan/report_generic.c
+++ b/mm/kasan/report_generic.c
@@ -148,7 +148,7 @@ static bool __must_check tokenize_frame_descr(const char **frame_descr,
}

/* Copy token (+ 1 byte for '\0'). */
- strlcpy(token, *frame_descr, tok_len + 1);
+ strscpy(token, *frame_descr, tok_len + 1);
}

/* Advance frame_descr past separator. */
--
1.8.3.1


2021-02-22 07:47:03

by Alexander Potapenko

[permalink] [raw]
Subject: Re: [PATCH] mm/kasan: switch from strlcpy to strscpy

On Mon, Feb 22, 2021 at 6:10 AM Zhiyuan Dai <[email protected]> wrote:
>
> strlcpy is marked as deprecated in Documentation/process/deprecated.rst,
> and there is no functional difference when the caller expects truncation
> (when not checking the return value). strscpy is relatively better as it
> also avoids scanning the whole source string.

Looks like a good thing to do.

> Signed-off-by: Zhiyuan Dai <[email protected]>
Acked-by: Alexander Potapenko <[email protected]>

> ---
> mm/kasan/report_generic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c
> index 8a9c889..fc7f7ad 100644
> --- a/mm/kasan/report_generic.c
> +++ b/mm/kasan/report_generic.c
> @@ -148,7 +148,7 @@ static bool __must_check tokenize_frame_descr(const char **frame_descr,
> }
>
> /* Copy token (+ 1 byte for '\0'). */
> - strlcpy(token, *frame_descr, tok_len + 1);
> + strscpy(token, *frame_descr, tok_len + 1);
> }
>
> /* Advance frame_descr past separator. */
> --
> 1.8.3.1
>


--
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

2021-02-25 01:00:01

by Andrey Konovalov

[permalink] [raw]
Subject: Re: [PATCH] mm/kasan: switch from strlcpy to strscpy

On Mon, Feb 22, 2021 at 8:45 AM Alexander Potapenko <[email protected]> wrote:
>
> On Mon, Feb 22, 2021 at 6:10 AM Zhiyuan Dai <[email protected]> wrote:
> >
> > strlcpy is marked as deprecated in Documentation/process/deprecated.rst,
> > and there is no functional difference when the caller expects truncation
> > (when not checking the return value). strscpy is relatively better as it
> > also avoids scanning the whole source string.
>
> Looks like a good thing to do.
>
> > Signed-off-by: Zhiyuan Dai <[email protected]>
> Acked-by: Alexander Potapenko <[email protected]>
>
> > ---
> > mm/kasan/report_generic.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c
> > index 8a9c889..fc7f7ad 100644
> > --- a/mm/kasan/report_generic.c
> > +++ b/mm/kasan/report_generic.c
> > @@ -148,7 +148,7 @@ static bool __must_check tokenize_frame_descr(const char **frame_descr,
> > }
> >
> > /* Copy token (+ 1 byte for '\0'). */
> > - strlcpy(token, *frame_descr, tok_len + 1);
> > + strscpy(token, *frame_descr, tok_len + 1);
> > }
> >
> > /* Advance frame_descr past separator. */
> > --
> > 1.8.3.1
> >

Reviewed-by: Andrey Konovalov <[email protected]>

Thanks!