]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: check dirent names when reading protofile
authorDarrick J. Wong <djwong@kernel.org>
Thu, 23 Feb 2023 21:29:39 +0000 (13:29 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 15 Mar 2023 00:47:29 +0000 (17:47 -0700)
The protofile parser in mkfs does not check directory entry names when
populating the filesystem.  The libxfs directory code doesn't check them
either, since they depend on the Linux VFS to sanitize incoming names.
If someone puts a slash in the first (name) column in the protofile,
this results in a successful format and xfs_repair -n immediately
complains.

Screen the names that are being read from the protofile.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
mkfs/proto.c

index 68ecdbf36325cb7c5640b42475c9eb53a2683fbe..7e3fc1b813492eb7f6f02f39fd49ad23b2aa8bd3 100644 (file)
@@ -326,6 +326,12 @@ newdirent(
        int     error;
        int     rsv;
 
+       if (!libxfs_dir2_namecheck(name->name, name->len)) {
+               fprintf(stderr, _("%.*s: invalid directory entry name\n"),
+                               name->len, name->name);
+               exit(1);
+       }
+
        rsv = XFS_DIRENTER_SPACE_RES(mp, name->len);
 
        error = -libxfs_dir_createname(tp, pip, name, inum, rsv);