mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/memfd: replace strcpy() by strscpy()
@ 2021-01-24  2:23 Stephen Zhang
  2021-01-24  4:06 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Zhang @ 2021-01-24  2:23 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Stephen Zhang

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(-)

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;
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/memfd: replace strcpy() by strscpy()
  2021-01-24  2:23 [PATCH] mm/memfd: replace strcpy() by strscpy() Stephen Zhang
@ 2021-01-24  4:06 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2021-01-24  4:06 UTC (permalink / raw)
  To: Stephen Zhang; +Cc: akpm, linux-mm, linux-kernel

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-24  4:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-24  2:23 [PATCH] mm/memfd: replace strcpy() by strscpy() Stephen Zhang
2021-01-24  4:06 ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®