* [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; 3+ 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 related [flat|nested] 3+ 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
2021-01-24 4:36 ` Stephen Zhang
0 siblings, 1 reply; 3+ 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] 3+ messages in thread
* Re: [PATCH] mm/memfd: replace strcpy() by strscpy()
2021-01-24 4:06 ` Matthew Wilcox
@ 2021-01-24 4:36 ` Stephen Zhang
0 siblings, 0 replies; 3+ messages in thread
From: Stephen Zhang @ 2021-01-24 4:36 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 521 bytes --]
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.
>
[-- Attachment #2: Type: text/html, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-24 4:36 UTC | newest]
Thread overview: 3+ 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
2021-01-24 4:36 ` Stephen Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).