From: Pranav Tyagi Date: Mon, 6 Oct 2025 12:40:18 +0000 (+0200) Subject: fs/xfs: replace strncpy with memtostr_pad() X-Git-Tag: v6.17.0~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=86c2579ddf30874ce5aa33760630792a4962f238;p=thirdparty%2Fxfsprogs-dev.git 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 Reviewed-by: Carlos Maiolino Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino Signed-off-by: Andrey Albershteyn Reviewed-by: "Darrick J. Wong" --- diff --git a/db/metadump.c b/db/metadump.c index 34f2d617..24eb99da 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -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)) diff --git a/include/platform_defs.h b/include/platform_defs.h index fa66551d..7b4a1a62 100644 --- a/include/platform_defs.h +++ b/include/platform_defs.h @@ -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__ */ diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 9566a762..779dac59 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -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 */