mm/memfd: replace strcpy() by strscpy()
Subsystems (2)
PATCH 1/1 mm/memfd: replace strcpy() by strscpy()
The strcpy() function is being deprecated. Replace it by the safer strscpy().
Signed-off-by Stephen Zhang <[email protected]>
--- mm/memfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memfd.c +1 -1
@@ -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;
Signature · 1 line
1.8.3.1
mm/memfd.c long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg) · line 281
Quoted 2 lines · Stephen Zhang
mm/memfd.c +1
-1-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?
Quoted 6 lines · Matthew Wilcox <[email protected]> 于2021年1月24日周日 下午12:08写道:
mm/memfd.c long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg) · line 281
Quoted 2 lines · Stephen Zhang
mm/memfd.c +1
-1-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.