Skip to content

Commit 6b343a4

Browse files
JustinStittkees
authored andcommitted
EDAC/mc_sysfs: Replace deprecated strncpy() with memcpy()
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. We've already calculated bounds, possible truncation with '\0' or '\n' and manually NUL-terminated. The situation is now just a literal byte copy from one buffer to another, let's treat it as such and use a less ambiguous interface in memcpy. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: KSPP#90 Cc: [email protected] Signed-off-by: Justin Stitt <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/20230918-strncpy-drivers-edac-edac_mc_sysfs-c-v4-1-38a23d2fcdd8@google.com Signed-off-by: Kees Cook <[email protected]>
1 parent 8046da4 commit 6b343a4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/edac/edac_mc_sysfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static ssize_t channel_dimm_label_store(struct device *dev,
229229
if (copy_count == 0 || copy_count >= sizeof(rank->dimm->label))
230230
return -EINVAL;
231231

232-
strncpy(rank->dimm->label, data, copy_count);
232+
memcpy(rank->dimm->label, data, copy_count);
233233
rank->dimm->label[copy_count] = '\0';
234234

235235
return count;
@@ -535,7 +535,7 @@ static ssize_t dimmdev_label_store(struct device *dev,
535535
if (copy_count == 0 || copy_count >= sizeof(dimm->label))
536536
return -EINVAL;
537537

538-
strncpy(dimm->label, data, copy_count);
538+
memcpy(dimm->label, data, copy_count);
539539
dimm->label[copy_count] = '\0';
540540

541541
return count;

0 commit comments

Comments
 (0)