diff options
author | Mark Johnston <markj@FreeBSD.org> | 2021-03-27 17:42:48 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2021-04-03 15:12:21 +0000 |
commit | ca20444e2ad664c34bb12f1a24f4ca6dc407a5bc (patch) | |
tree | 35511d6f2f36bbdcba52553c765bbb9060c15133 | |
parent | e3b1b9d625ca6e816b91e0e58142cfc7743cacb8 (diff) | |
download | src-ca20444e2ad664c34bb12f1a24f4ca6dc407a5bc.tar.gz src-ca20444e2ad664c34bb12f1a24f4ca6dc407a5bc.zip |
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@gmail.com>
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29431
(cherry picked from commit 71c160a8f614fa4812838002ba9d266af3cf988c)
-rw-r--r-- | sys/kern/vfs_lookup.c | 9 |
1 files changed, 9 insertions, 0 deletions
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> @@ -748,6 +749,14 @@ needs_exclusive_leaf(struct mount *mp, int flags) } /* + * 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. * |