mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-26 04:16:39 +00:00
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: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230918-strncpy-drivers-edac-edac_mc_sysfs-c-v4-1-38a23d2fcdd8@google.com Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
parent
8046da444d
commit
6b343a4642
1 changed files with 2 additions and 2 deletions
|
@ -229,7 +229,7 @@ static ssize_t channel_dimm_label_store(struct device *dev,
|
|||
if (copy_count == 0 || copy_count >= sizeof(rank->dimm->label))
|
||||
return -EINVAL;
|
||||
|
||||
strncpy(rank->dimm->label, data, copy_count);
|
||||
memcpy(rank->dimm->label, data, copy_count);
|
||||
rank->dimm->label[copy_count] = '\0';
|
||||
|
||||
return count;
|
||||
|
@ -535,7 +535,7 @@ static ssize_t dimmdev_label_store(struct device *dev,
|
|||
if (copy_count == 0 || copy_count >= sizeof(dimm->label))
|
||||
return -EINVAL;
|
||||
|
||||
strncpy(dimm->label, data, copy_count);
|
||||
memcpy(dimm->label, data, copy_count);
|
||||
dimm->label[copy_count] = '\0';
|
||||
|
||||
return count;
|
||||
|
|
Loading…
Reference in a new issue