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

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

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

On 2021-09-03 08:05, Len Baker wrote:
strcpy() performs no bounds checking on the destination buffer. 
len.baker@gmx.com/
[]
quoted hunk ↗ jump to hunk
@@ -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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help