]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: check directory name validity
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 6 May 2019 22:00:20 +0000 (18:00 -0400)
committerEric Sandeen <sandeen@redhat.com>
Mon, 6 May 2019 22:00:20 +0000 (18:00 -0400)
Source kernel commit: e5d7d51b340aac0f4cc56677eb8d29d4e164c58c

Check directory entry names for invalid characters.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_dir2.c
libxfs/xfs_dir2.h

index b0ad4a8b797f7c8df648ae2555e753407858aeeb..6b51a5253942d650b77a0d981368def39b1a40c9 100644 (file)
@@ -701,3 +701,20 @@ xfs_dir2_shrink_inode(
        xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
        return 0;
 }
+
+/* Returns true if the directory entry name is valid. */
+bool
+xfs_dir2_namecheck(
+       const void      *name,
+       size_t          length)
+{
+       /*
+        * MAXNAMELEN includes the trailing null, but (name/length) leave it
+        * out, so use >= for the length check.
+        */
+       if (length >= MAXNAMELEN)
+               return false;
+
+       /* There shouldn't be any slashes or nulls here */
+       return !memchr(name, '/', length) && !memchr(name, 0, length);
+}
index c3e3f6b813d869cb2f7a78bebc3b2a5765ab58ed..f542447794928e47c9eba683690866e105506aaa 100644 (file)
@@ -326,5 +326,6 @@ xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp)
 unsigned char xfs_dir3_get_dtype(struct xfs_mount *mp, uint8_t filetype);
 void *xfs_dir3_data_endp(struct xfs_da_geometry *geo,
                struct xfs_dir2_data_hdr *hdr);
+bool xfs_dir2_namecheck(const void *name, size_t length);
 
 #endif /* __XFS_DIR2_H__ */