]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/memfd: replace deprecated strcpy() with memcpy() in alloc_name()
authorThorsten Blum <thorsten.blum@linux.dev>
Sat, 12 Jul 2025 17:45:17 +0000 (19:45 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 20 Jul 2025 01:59:57 +0000 (18:59 -0700)
strcpy() is deprecated; use memcpy() instead.

Not copying the NUL terminator is safe because strncpy_from_user() would
overwrite it anyway by appending uname to the destination buffer at index
MFD_NAME_PREFIX_LEN.

No functional changes intended.

Link: https://github.com/KSPP/linux/issues/88
Link: https://lkml.kernel.org/r/20250712174516.64243-2-thorsten.blum@linux.dev
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memfd.c

index 32fa6bfe57d11ac132ae41548d1156c901f8e505..bbe679895ef6a191badd56bc4c814b7bc9adfee1 100644 (file)
@@ -411,7 +411,7 @@ static char *alloc_name(const char __user *uname)
        if (!name)
                return ERR_PTR(-ENOMEM);
 
-       strcpy(name, MFD_NAME_PREFIX);
+       memcpy(name, MFD_NAME_PREFIX, MFD_NAME_PREFIX_LEN);
        /* returned length does not include terminating zero */
        len = strncpy_from_user(&name[MFD_NAME_PREFIX_LEN], uname, MFD_NAME_MAX_LEN + 1);
        if (len < 0) {