]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ocfs2: replace deprecated strcpy in ocfs2_create_xattr_block
authorThorsten Blum <thorsten.blum@linux.dev>
Tue, 18 Nov 2025 18:53:44 +0000 (19:53 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 20 Nov 2025 22:03:45 +0000 (14:03 -0800)
strcpy() has been deprecated [1] because it performs no bounds checking on
the destination buffer, which can lead to buffer overflows.  Replace it
with the safer strscpy(), and copy directly into '->xb_signature' instead
of using the start of the struct as the destination buffer.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Link: https://lkml.kernel.org/r/20251118185345.132411-2-thorsten.blum@linux.dev
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ocfs2/xattr.c

index d70a20d29e3e94b8bdc4488c0275b335794389c9..73c028f452aca5d4f7fc80b0c38c35fda87e6dd1 100644 (file)
@@ -2908,7 +2908,7 @@ static int ocfs2_create_xattr_block(struct inode *inode,
        /* Initialize ocfs2_xattr_block */
        xblk = (struct ocfs2_xattr_block *)new_bh->b_data;
        memset(xblk, 0, inode->i_sb->s_blocksize);
-       strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE);
+       strscpy(xblk->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE);
        xblk->xb_suballoc_slot = cpu_to_le16(ctxt->meta_ac->ac_alloc_slot);
        xblk->xb_suballoc_loc = cpu_to_le64(suballoc_loc);
        xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start);