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

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

From: Robert Richter <rric@kernel.org>
Date: 2021-08-11 07:40:42
Also in: linux-hardening, lkml

On 10.08.21 08:02:17, Joe Perches wrote:
On Tue, 2021-08-10 at 16:36 +0200, Robert Richter wrote:
quoted
On 09.08.21 10:18:58, Joe Perches wrote:
quoted
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.
Calculating the bytes written from the return value is a oneliner.
Not really.
You still have to test for strscpy's possible return of -E2BIG.
I thought of:

	num = strscpy(p, OTHER_LABEL, len);
	num = num < 0 ? len : num;
	len -= num;
	p += num;

Clearly, this does not look nice, esp. if this is repeated in the
code. That's why I prefer the strlen(p) implementation:

	strscpy(p, OTHER_LABEL, len);
	len -= strlen(p);
	p += strlen(p);

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