Thread (11 messages) 11 messages, 4 authors, 2021-08-11

Re: [PATCH v3] drivers/edac/edac_mc: Remove all strcpy() uses

From: Joe Perches <joe@perches.com>
Date: 2021-08-09 17:19:07
Also in: linux-hardening, lkml

On Mon, 2021-08-09 at 12:05 +0200, Robert Richter wrote:
On 08.08.21 13:26:17, Len Baker wrote:
quoted
quoted
Perhaps this should use scnprintf rather than strscpy
Something like:
			n += scnprintf(buf + n, len - n, "%s",
				       p == e->label ? dim->label : OTHER_LABEL);
In the first version [1] the scnprintf was used but Robert Richter don't
see any benefit compared with the current implementation.

[1] https://lore.kernel.org/linux-hardening/20210725162954.9861-1-len.baker@gmx.com/ (local)
Reason is that there is the assumption that p must always point at the
end of the string and its trailing zero byte. I am not opposed using
the string function's return code instead of strlen() to get the
length. But why using formated output if strscpy() can be used?
strscpy and scnprintf have different return values and it's simpler
and much more common to use scnprintf for appended strings that are
limited to a specific buffer length.


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help