]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
fs/xfs: replace strncpy with memtostr_pad()
authorPranav Tyagi <pranav.tyagi03@gmail.com>
Mon, 6 Oct 2025 12:40:18 +0000 (14:40 +0200)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 13 Oct 2025 09:53:39 +0000 (11:53 +0200)
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>
Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
db/metadump.c
include/platform_defs.h
libxfs/xfs_format.h

index 34f2d61700fe1d1746e7a4bdad313eb72a6f366c..24eb99da172396ecab89be53570c1563da84882b 100644 (file)
@@ -2989,7 +2989,7 @@ scan_ag(
                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))
index fa66551d99ff02de53497782ab66cc7dff7636a8..7b4a1a625586dbc055b42c30b7ab60e4025c1e42 100644 (file)
@@ -296,4 +296,10 @@ static inline bool __must_check __must_check_overflow(bool overflow)
 
 #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__ */
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 */