Skip to contentSkip to conversation

mm/memfd: replace strcpy() by strscpy()

PATCH In review Stephen Zhang 2 participants 3 messages Jan 24, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/memfd: replace strcpy() by strscpy()

The strcpy() function is being deprecated. Replace it by the safer strscpy().

---
 mm/memfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memfd.c +1 -1
index 2647c89..bb90862 100644
@@ -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
#1 lore raw

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.

#2 lore raw

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.