makefs: Add some validation of ZFS pool names
Reported by: imp
This commit is contained in:
parent
38d2b4db78
commit
a9e7a44c24
@ -33,6 +33,7 @@
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdalign.h>
|
||||
#include <stdbool.h>
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user