]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/xfs: replace strncpy with memtostr_pad()
authorPranav Tyagi <pranav.tyagi03@gmail.com>
Fri, 4 Jul 2025 10:12:50 +0000 (15:42 +0530)
committerCarlos Maiolino <cem@kernel.org>
Thu, 24 Jul 2025 15:30:14 +0000 (17:30 +0200)
Replace the deprecated strncpy() with memtostr_pad(). This also avoids
the need for separate zeroing using memset(). Mark sb_fname buffer with
__nonstring as its size is XFSLABEL_MAX and so no terminating NULL for
sb_fname.

Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/libxfs/xfs_format.h
fs/xfs/xfs_ioctl.c

index 9566a76233654004d54f47aac17ac60dd8a6629a..779dac59b1f3babd10f52e4c1893f84c1d34ed52 100644 (file)
@@ -112,7 +112,7 @@ typedef struct xfs_sb {
        uint16_t        sb_sectsize;    /* volume sector size, bytes */
        uint16_t        sb_inodesize;   /* inode size, bytes */
        uint16_t        sb_inopblock;   /* inodes per block */
-       char            sb_fname[XFSLABEL_MAX]; /* file system name */
+       char            sb_fname[XFSLABEL_MAX] __nonstring; /* file system name */
        uint8_t         sb_blocklog;    /* log2 of sb_blocksize */
        uint8_t         sb_sectlog;     /* log2 of sb_sectsize */
        uint8_t         sb_inodelog;    /* log2 of sb_inodesize */
index d250f7f74e3b63078fdc8aaaceb9a74e664d4ac1..c3e8c5c1084f65c9ed30c92923b264a199dfbd40 100644 (file)
@@ -990,9 +990,8 @@ xfs_ioc_getlabel(
        BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX);
 
        /* 1 larger than sb_fname, so this ensures a trailing NUL char */
-       memset(label, 0, sizeof(label));
        spin_lock(&mp->m_sb_lock);
-       strncpy(label, sbp->sb_fname, XFSLABEL_MAX);
+       memtostr_pad(label, sbp->sb_fname);
        spin_unlock(&mp->m_sb_lock);
 
        if (copy_to_user(user_label, label, sizeof(label)))