Skip to contentSkip to conversation

edac: edac_mc_sysfs.c: Use strlcpy to Copy a C-string into a sized buffer

PATCH Superseded Karim Eshapa 1 participant 1 message May 26, 2017 EDAC-core

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 edac: edac_mc_sysfs.c: Use strlcpy to Copy a C-string into a sized buffer

Use strlcpy with sized buffer instead of strncpy to avoid non NUL-terminated source strings problems.

---
 drivers/edac/edac_mc_sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/edac_mc_sysfs.c +2 -2
index 445862d..64e2255 100644
@@ -251,7 +251,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);
+	strlcpy(rank->dimm->label, data, copy_count);
 	rank->dimm->label[copy_count] = '\0';
 
 	return count;
@@ -530,7 +530,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);
+	strlcpy(dimm->label, data, copy_count);
 	dimm->label[copy_count] = '\0';
 
 	return count;