[PATCH] EDAC/mc: Prefer strscpy or scnprintf over strcpy, sprintf and snprintf

From: Robert Richter
Date: Mon Sep 13 2021 - 04:59:23 EST


Len,

On 03.09.21 17:05:39, Len Baker wrote:
> strcpy() performs no bounds checking on the destination buffer. This
> could result in linear overflows beyond the end of the buffer, leading
> to all kinds of misbehaviors. The safe replacement is strscpy() [1].
>
> However, to simplify and clarify the code, to concatenate labels use
> the scnprintf() function. This way it is not necessary to check the
> return value of strscpy (-E2BIG if the parameter count is 0 or the src
> was truncated) since the scnprintf returns always the number of chars
> written into the buffer. This function returns always a nul-terminated
> string even if it needs to be truncated.
>
> The main reason behind this patch is to remove all the strcpy() uses
> from the kernel with the purpose to clean up the proliferation of
> str*cpy() functions. Later on, the next step will be remove all the
> strcpy implementations [2].
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
> [2] https://github.com/KSPP/linux/issues/88
>
> Co-developed-by: Joe Perches <joe@xxxxxxxxxxx>
> Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
> Signed-off-by: Len Baker <len.baker@xxxxxxx>

this patch looks good to me. I made some changes on top of it to
further ease pointer arithmetic and also fix remaining
sprintf/snprintf() users as it makes sense to have them all in a
single change. See below. Boris, please apply.

Thanks,

-Robert