RE: [PATCH net 3/4] net: dsa: microchip: Utilize strncpy() for ethtool::get_strings

From: David Laight
Date: Fri Mar 02 2018 - 05:51:15 EST


From: Florian Fainelli
>
> Do not use memcpy() which is not safe, but instead use strncpy() which
> will make sure that the string is NUL terminated (in the Linux
> implementation) if the string is smaller than the length specified. This
> fixes KASAN out of bounds warnings while fetching port statistics.

You really ought to use a copy function that will truncate the
string if it is too long.
Just assuming the string isn't too long is asking for trouble.
You might (almost) just use strcpy().

strlcpy() will probably work best here.

David