From: Darrick J. Wong Date: Tue, 23 Sep 2025 17:10:27 +0000 (-0700) Subject: libfrog: pass mode to xfrog_file_setattr X-Git-Tag: v6.17.0~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e51aa35ec4c8da806f6dc79a2eb03abae7ef99da;p=thirdparty%2Fxfsprogs-dev.git libfrog: pass mode to xfrog_file_setattr xfs/633 crashes rdump_fileattrs_path passes a NULL struct stat pointer and then the fallback code dereferences it to get the file mode. Instead, let's just pass the stat mode directly to it, because that's the only piece of information that it needs. Fixes: 128ac4dadbd633 ("xfs_db: use file_setattr to copy attributes on special files with rdump") Signed-off-by: Darrick J. Wong Reviewed-by: Andrey Albershteyn --- diff --git a/db/rdump.c b/db/rdump.c index 82520e37d..a50df4b8c 100644 --- a/db/rdump.c +++ b/db/rdump.c @@ -188,8 +188,8 @@ rdump_fileattrs_path( return 1; } - ret = xfrog_file_setattr(destdir->fd, pbuf->path, NULL, &fa, - AT_SYMLINK_NOFOLLOW); + ret = xfrog_file_setattr(destdir->fd, pbuf->path, VFS_I(ip)->i_mode, + &fa, AT_SYMLINK_NOFOLLOW); if (ret) { if (errno == EOPNOTSUPP || errno == EPERM || errno == ENOTTY) lost_mask |= LOST_FSXATTR; diff --git a/io/attr.c b/io/attr.c index 022ca5f1d..9563ff74e 100644 --- a/io/attr.c +++ b/io/attr.c @@ -261,7 +261,7 @@ chattr_callback( attr.fa_xflags |= orflags; attr.fa_xflags &= ~andflags; - error = xfrog_file_setattr(AT_FDCWD, path, stat, &attr, + error = xfrog_file_setattr(AT_FDCWD, path, stat->st_mode, &attr, AT_SYMLINK_NOFOLLOW); if (error) { fprintf(stderr, _("%s: cannot set flags on %s: %s\n"), @@ -357,7 +357,7 @@ chattr_f( attr.fa_xflags |= orflags; attr.fa_xflags &= ~andflags; - error = xfrog_file_setattr(AT_FDCWD, name, &st, &attr, + error = xfrog_file_setattr(AT_FDCWD, name, st.st_mode, &attr, AT_SYMLINK_NOFOLLOW); if (error) { fprintf(stderr, _("%s: cannot set flags on %s: %s\n"), diff --git a/libfrog/file_attr.c b/libfrog/file_attr.c index bb51ac6eb..c2cbcb4e1 100644 --- a/libfrog/file_attr.c +++ b/libfrog/file_attr.c @@ -85,7 +85,7 @@ int xfrog_file_setattr( const int dfd, const char *path, - const struct stat *stat, + const mode_t mode, struct file_attr *fa, const unsigned int at_flags) { @@ -103,7 +103,7 @@ xfrog_file_setattr( return error; #endif - if (SPECIAL_FILE(stat->st_mode)) { + if (SPECIAL_FILE(mode)) { errno = EOPNOTSUPP; return -1; } diff --git a/libfrog/file_attr.h b/libfrog/file_attr.h index df9b6181d..2a1c0d42d 100644 --- a/libfrog/file_attr.h +++ b/libfrog/file_attr.h @@ -24,12 +24,7 @@ xfrog_file_getattr( struct file_attr *fa, const unsigned int at_flags); -int -xfrog_file_setattr( - const int dfd, - const char *path, - const struct stat *stat, - struct file_attr *fa, - const unsigned int at_flags); +int xfrog_file_setattr(const int dfd, const char *path, const mode_t mode, + struct file_attr *fa, const unsigned int at_flags); #endif /* __LIBFROG_FILE_ATTR_H__ */ diff --git a/quota/project.c b/quota/project.c index 5832e1474..33449e01e 100644 --- a/quota/project.c +++ b/quota/project.c @@ -157,7 +157,8 @@ clear_project( fa.fa_projid = 0; fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT; - error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW); + error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa, + AT_SYMLINK_NOFOLLOW); if (error) { fprintf(stderr, _("%s: cannot clear project on %s: %s\n"), progname, path, strerror(errno)); @@ -205,7 +206,8 @@ setup_project( if (S_ISDIR(stat->st_mode)) fa.fa_xflags |= FS_XFLAG_PROJINHERIT; - error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW); + error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa, + AT_SYMLINK_NOFOLLOW); if (error) { fprintf(stderr, _("%s: cannot set project on %s: %s\n"), progname, path, strerror(errno));