Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1651580
| From | Karim Eshapa <karim.eshapa@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2] edac: edac_mc_sysfs.c: Use strlcpy to Copy a C-string into a sized buffer |
| Date | 2017-05-26 21:20 +0200 |
| Message-ID | <tLsWe-1pQ-23@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
Use strlcpy with sized buffer instead of strncpy to avoid non NUL-terminated source strings problems. Signed-off-by: Karim Eshapa <karim.eshapa@gmail.com> --- drivers/edac/edac_mc_sysfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index 445862d..e893b94 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -251,8 +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); - rank->dimm->label[copy_count] = '\0'; + strlcpy(rank->dimm->label, data, copy_count); return count; } @@ -530,8 +529,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); - dimm->label[copy_count] = '\0'; + strlcpy(dimm->label, data, copy_count); return count; } -- 2.7.4
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH v2] edac: edac_mc_sysfs.c: Use strlcpy to Copy a C-string into a sized buffer Karim Eshapa <karim.eshapa@gmail.com> - 2017-05-26 21:20 +0200 Re: [PATCH v2] edac: edac_mc_sysfs.c: Use strlcpy to Copy a C-string into a sized buffer Borislav Petkov <bp@alien8.de> - 2017-05-28 20:20 +0200
csiph-web