Whamcloud - gitweb
LU-16060 osd-ldiskfs: copy nul byte terminator in writelink 56/51356/3
authorAlexander Zarochentsev <alexander.zarochentsev@hpe.com>
Wed, 20 Jul 2022 16:05:53 +0000 (19:05 +0300)
committerOleg Drokin <green@whamcloud.com>
Thu, 19 Oct 2023 13:47:02 +0000 (13:47 +0000)
memcpy() call in osd_ldiskfs_writelink() doesn't copy the nul
terminator byte from the source buffer, leaving the space
after target link name uninialized which is ok for the kernel
code and debugfs but not e2fsck.

HPE-bug-id: LUS-11103

Lustre-change: https://review.whamcloud.com/48092
Lustre-commit: 907dc0a2d333f2df2d654a968fc50f8cc05b779d

Signed-off-by: Alexander Zarochentsev <alexander.zarochentsev@hpe.com>
Change-Id: I914f2c78e1a6571bf360a23b0ede8c70502bf0df
Reviewed-by: Artem Blagodarenko <ablagodarenko@ddn.com>
Reviewed-by: Andrew Perepechko <andrew.perepechko@hpe.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Etienne AUJAMES <eaujames@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51356
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/osd-ldiskfs/osd_io.c

index f44420d..7131add 100644 (file)
@@ -2022,7 +2022,8 @@ static int osd_ldiskfs_writelink(struct inode *inode, char *buffer, int buflen)
        /* LU-2634: clear the extent format for fast symlink */
        ldiskfs_clear_inode_flag(inode, LDISKFS_INODE_EXTENTS);
 
-       memcpy((char *)&LDISKFS_I(inode)->i_data, (char *)buffer, buflen);
+       /* Copying the NUL byte terminating the link target as well */
+       memcpy((char *)&LDISKFS_I(inode)->i_data, (char *)buffer, buflen + 1);
        spin_lock(&inode->i_lock);
        LDISKFS_I(inode)->i_disksize = buflen;
        i_size_write(inode, buflen);