fs/xfs: replace strncpy with memtostr_pad()
PATCH v2 1/1 fs/xfs: replace strncpy with memtostr_pad()
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.
--- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/xfs_ioctl.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_format.h +1 -1
@@ -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 */
fs/xfs/xfs_ioctl.c +1 -2
@@ -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)))
Signature · 1 line
2.49.0
Quoted 41 lines · Pranav Tyagi
Replace the deprecated
strncpy()withmemtostr_pad(). This also avoids the need for separate zeroing usingmemset(). Marksb_fnamebuffer with__nonstringas its size isXFSLABEL_MAXand so no terminating NULL forsb_fname.Signed-off-by Pranav Tyagi <[email protected]>--- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/xfs_ioctl.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_format.h +1
-1@@ -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 */ fs/xfs/xfs_ioctl.c +1
-3@@ -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))) --
Quoted 2 lines
2.49.0
Hi,
This is a gentle follow-up on this patch. I would like to know if there is any update on its state.
Regards
Pranav Tyagi
Darrick J. Wong
Reviewed-byQuoted 40 lines · Pranav Tyagi
Quoted 39 lines · Pranav Tyagi
Replace the deprecated
strncpy()withmemtostr_pad(). This also avoids the need for separate zeroing usingmemset(). Marksb_fnamebuffer with__nonstringas its size isXFSLABEL_MAXand so no terminating NULL forsb_fname.Signed-off-by Pranav Tyagi <[email protected]>--- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/xfs_ioctl.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_format.h +1
-1@@ -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 */ fs/xfs/xfs_ioctl.c +1
-2@@ -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);
Quoted 8 lines
Quoted 4 lines
fs/xfs/xfs_ioctl.c +0
-1if (copy_to_user (user_label, label,sizeof (label))) --2.49.0
Hi,
This is a gentle follow-up on this patch. I would like to know if there is any update on its state.
Seems fine to me...
--D
Quoted 4 lines
Regards
Pranav Tyagi
Quoted 40 lines · Pranav Tyagi
Quoted 39 lines · Pranav Tyagi
Replace the deprecated
strncpy()withmemtostr_pad(). This also avoids the need for separate zeroing usingmemset(). Marksb_fnamebuffer with__nonstringas its size isXFSLABEL_MAXand so no terminating NULL forsb_fname.Signed-off-by Pranav Tyagi <[email protected]>--- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/xfs_ioctl.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_format.h +1
-1@@ -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 */ fs/xfs/xfs_ioctl.c +1
-2@@ -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);
Quoted 8 lines
Quoted 4 lines
fs/xfs/xfs_ioctl.c +0
-1if (copy_to_user (user_label, label,sizeof (label))) --2.49.0
Hi,
This is a gentle follow-up on this patch. I would like to know if there is any update on its state.
Looks fine to me:
Quoted 4 lines
Regards
Pranav Tyagi
Quoted 6 lines · Pranav Tyagi
Replace the deprecated
strncpy()withmemtostr_pad(). This also avoids the need for separate zeroing usingmemset(). Marksb_fnamebuffer with__nonstringas its size isXFSLABEL_MAXand so no terminating NULL forsb_fname.
Applied to for-next, thanks!
[1/1] fs/xfs: replace strncpy with memtostr_pad()
commit: f161da9418910f4ab7a29099682d03e06ef2c3ef
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>