Re: [PATCH] net: dl2k: replace strlcpy with strscpy

From: Arnd Bergmann
Date: Tue Dec 21 2021 - 04:23:59 EST


On Tue, Dec 21, 2021 at 8:14 AM Jason Wang <wangborong@xxxxxxxxxx> wrote:
>
> The strlcpy should not be used because it doesn't limit the source
> length. So that it will lead some potential bugs.
>
> But the strscpy doesn't require reading memory from the src string
> beyond the specified "count" bytes, and since the return value is
> easier to error-check than strlcpy()'s. In addition, the implementation
> is robust to the string changing out from underneath it, unlike the
> current strlcpy() implementation.
>
> Thus, replace strlcpy with strscpy.
>
> Signed-off-by: Jason Wang <wangborong@xxxxxxxxxx>

Are you trying to eliminate strlcpy() from all 800 files using it
completely? If not, I don't see a need to fix individual drivers
that use a constant source string and don't use the return
code, as the behavior should be the same.

While it seems reasonable to converge towards a more robust
string copy, none of the points you list in the changelog apply to
the function you patch here.

Arnd