Message ID | 1611455017-2210-1-git-send-email-stephenzhangzsd@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mm/memfd: replace strcpy() by strscpy() | expand |
On Sun, Jan 24, 2021 at 10:23:37AM +0800, Stephen Zhang wrote: > - strcpy(name, MFD_NAME_PREFIX); > + strscpy(name, MFD_NAME_PREFIX, len + MFD_NAME_PREFIX_LEN); This is silly. Use memcpy() if you must remove strcpy.
Thanks for your suggestions. I just thought both of them are better than the deprecated strcpy(). Should I resubmit the patch after making changes or just leave it as it originally is? Matthew Wilcox <willy@infradead.org> 于2021年1月24日周日 下午12:08写道: > On Sun, Jan 24, 2021 at 10:23:37AM +0800, Stephen Zhang wrote: > > - strcpy(name, MFD_NAME_PREFIX); > > + strscpy(name, MFD_NAME_PREFIX, len + MFD_NAME_PREFIX_LEN); > > This is silly. Use memcpy() if you must remove strcpy. >
diff --git a/mm/memfd.c b/mm/memfd.c index 2647c89..bb90862 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -278,7 +278,7 @@ long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg) if (!name) return -ENOMEM; - strcpy(name, MFD_NAME_PREFIX); + strscpy(name, MFD_NAME_PREFIX, len + MFD_NAME_PREFIX_LEN); if (copy_from_user(&name[MFD_NAME_PREFIX_LEN], uname, len)) { error = -EFAULT; goto err_name;
The strcpy() function is being deprecated. Replace it by the safer strscpy(). Signed-off-by: Stephen Zhang <stephenzhangzsd@gmail.com> --- mm/memfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)