Re: [PATCH v3] kdb: Replace deprecated strcpy() with strscpy() and memcpy()

From: Thorsten Blum
Date: Fri Aug 15 2025 - 07:28:47 EST


Hi Daniel,

> On 15. Aug 2025, at 10:57, Daniel Thompson wrote:
> Sorry but a strscpy() where the length of the destination buffer has
> been calculated from the source string is way too much of a red flag
> for me.
>
> Put another way if there are "no functional changes intended" then there
> cannot possibly be any security benefit from replacing the "unsafe"
> strcpy() with the "safe" strscpy(). Likewise abusing the destination
> length argument to truncate a string makes the code shorter but *not*
> clearer because it's too easy to misread.

Deliberately truncating the source using strscpy() is a valid use case.
strscpy() allows the size argument to be smaller than the destination
buffer, so this is an intended use of the size argument, not an abuse.

From the strscpy() function comment in linux/string.h:

* The size argument @... is only required when @dst is not an array, or
* when the copy needs to be smaller than sizeof(@dst).

Thanks,
Thorsten