Thread (8 messages) flat view 8 messages, 4 authors, 2021-09-18

Re: [PATCH v6] EDAC/mc: Prefer strscpy or scnprintf over strcpy

From: Len Baker <hidden>
Date: 2021-09-04 11:23:36
Also in: linux-hardening, lkml

Hi,

On Fri, Sep 03, 2021 at 10:03:18AM -0700, Joe Perches wrote:
On 2021-09-03 08:05, Len Baker wrote:
quoted
strcpy() performs no bounds checking on the destination buffer.
len.baker@gmx.com/
[]
quoted
@@ -1113,12 +1115,9 @@ void edac_mc_handle_error(const enum
hw_event_mc_err_type type,
 			p = e->label;
 			*p = '\0';
 		} else {
-			if (p != e->label) {
-				strcpy(p, OTHER_LABEL);
-				p += strlen(OTHER_LABEL);
-			}
-			strcpy(p, dimm->label);
-			p += strlen(p);
+			n += scnprintf(e->label + n, sizeof(e->label) - n,
+				       "%s%s", prefix, dimm->label);
+			prefix = OTHER_LABEL;
OTHER_LABEL is a define specific to this module

IMO: Used once text macros are just obfuscating and should be removed.
This macro is used in "/include/linux/edac.h" as follows:

struct edac_raw_error_desc {
	[...]
	char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABELS];
	[...]
};

If we remove this define the size of label would be:

	char label[(EDAC_MC_LABEL_LEN + 6) * EDAC_MAX_LABELS];

So, I think now is more complicated to understand because the size is
what it is. If you prefer this option, I can remove the macro and add
a comment with some explanation.

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