From a9e7a44c243671647180160fc448a3ef3950f55c Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Fri, 16 Dec 2022 10:25:35 -0500 Subject: [PATCH] makefs: Add some validation of ZFS pool names Reported by: imp --- usr.sbin/makefs/zfs.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/usr.sbin/makefs/zfs.c b/usr.sbin/makefs/zfs.c index b92d08734d59..e86f838e8b5c 100644 --- a/usr.sbin/makefs/zfs.c +++ b/usr.sbin/makefs/zfs.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -215,6 +216,19 @@ zfs_check_opts(fsinfo_t *fsopts) if (zfs->poolname == NULL) errx(1, "a pool name must be specified"); + if (!isalpha(zfs->poolname[0])) + errx(1, "the pool name must begin with a letter"); + for (size_t i = 0, len = strlen(zfs->poolname); i < len; i++) { + if (!isalnum(zfs->poolname[i]) && zfs->poolname[i] != '_') + errx(1, "invalid character '%c' in pool name", + zfs->poolname[i]); + } + if (strcmp(zfs->poolname, "mirror") == 0 || + strcmp(zfs->poolname, "raidz") == 0 || + strcmp(zfs->poolname, "draid") == 0) { + errx(1, "pool name '%s' is reserved and cannot be used", + zfs->poolname); + } if (zfs->rootpath == NULL) easprintf(&zfs->rootpath, "/%s", zfs->poolname);