fs/xfs: replace strncpy with memtostr_pad()
Source kernel commit: f4a3f01e8e451fb3cb444a95a59964f4bc746902
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>
diff --git a/db/metadump.c b/db/metadump.c
index 34f2d61..24eb99d 100644
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -2989,7 +2989,7 @@
if (metadump.obfuscate) {
struct xfs_sb *sb = iocur_top->data;
memset(sb->sb_fname, 'L',
- min(strlen(sb->sb_fname), sizeof(sb->sb_fname)));
+ strnlen(sb->sb_fname, sizeof(sb->sb_fname)));
iocur_top->need_crc = 1;
}
if (write_buf(iocur_top))
diff --git a/include/platform_defs.h b/include/platform_defs.h
index fa66551..7b4a1a6 100644
--- a/include/platform_defs.h
+++ b/include/platform_defs.h
@@ -296,4 +296,10 @@
#define cmp_int(l, r) ((l > r) - (l < r))
+#if __has_attribute(__nonstring__)
+# define __nonstring __attribute__((__nonstring__))
+#else
+# define __nonstring
+#endif
+
#endif /* __XFS_PLATFORM_DEFS_H__ */
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index 9566a76..779dac5 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -112,7 +112,7 @@
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 */