git: 71c160a8f614 - main - vfs: Add an assertion around name length limits

Mark Johnston markj at FreeBSD.org
Sat Mar 27 17:45:27 UTC 2021


The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=71c160a8f614fa4812838002ba9d266af3cf988c

commit 71c160a8f614fa4812838002ba9d266af3cf988c
Author:     Mark Johnston <markj at FreeBSD.org>
AuthorDate: 2021-03-27 17:42:48 +0000
Commit:     Mark Johnston <markj at FreeBSD.org>
CommitDate: 2021-03-27 17:45:19 +0000

    vfs: Add an assertion around name length limits
    
    Some filesystems assume that they can copy a name component, with length
    bounded by NAME_MAX, into a dirent buffer of size MAXNAMLEN.  These
    constants have the same value; add a compile-time assertion to that
    effect.
    
    Reported by:    Alexey Kulaev <alex.qart at gmail.com>
    Reviewed by:    kib
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D29431
---
 sys/kern/vfs_lookup.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index e881e8f909a4..07c89e634de4 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/dirent.h>
 #include <sys/kernel.h>
 #include <sys/capsicum.h>
 #include <sys/fcntl.h>
@@ -747,6 +748,14 @@ needs_exclusive_leaf(struct mount *mp, int flags)
 	return (0);
 }
 
+/*
+ * Various filesystems expect to be able to copy a name component with length
+ * bounded by NAME_MAX into a directory entry buffer of size MAXNAMLEN.  Make
+ * sure that these are the same size.
+ */
+_Static_assert(MAXNAMLEN == NAME_MAX,
+    "MAXNAMLEN and NAME_MAX have different values");
+
 /*
  * Search a pathname.
  * This is a very central and rather complicated routine.


More information about the dev-commits-src-main mailing list