From 46952300210647faeef391e2df2a59ec6a185591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 22 Jan 2022 23:41:36 +0100 Subject: [PATCH] zfs: get: only accept whole type for -t, not tp[=whatever] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #12996 --- cmd/zfs/zfs_main.c | 52 ++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index b7a26242b0..2db42dfc69 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -1997,7 +1997,7 @@ zfs_do_get(int argc, char **argv) zprop_get_cbdata_t cb = { 0 }; int i, c, flags = ZFS_ITER_ARGS_CAN_BE_PATHS; int types = ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK; - char *value, *fields; + char *fields; int ret = 0; int limit = 0; zprop_list_t fake_name = { 0 }; @@ -2115,37 +2115,29 @@ found2:; case 't': types = 0; flags &= ~ZFS_ITER_PROP_LISTSNAPS; - while (*optarg != '\0') { - static char *type_subopts[] = { "filesystem", - "volume", "snapshot", "snap", "bookmark", - "all", NULL }; - switch (getsubopt(&optarg, type_subopts, - &value)) { - case 0: - types |= ZFS_TYPE_FILESYSTEM; - break; - case 1: - types |= ZFS_TYPE_VOLUME; - break; - case 2: - case 3: - types |= ZFS_TYPE_SNAPSHOT; - break; - case 4: - types |= ZFS_TYPE_BOOKMARK; - break; - case 5: - types = ZFS_TYPE_DATASET | - ZFS_TYPE_BOOKMARK; - break; + for (char *tok; (tok = strsep(&optarg, ",")); ) { + static const char *const type_opts[] = { + "filesystem", "volume", + "snapshot", "snap", + "bookmark", + "all" }; + static const int type_types[] = { + ZFS_TYPE_FILESYSTEM, ZFS_TYPE_VOLUME, + ZFS_TYPE_SNAPSHOT, ZFS_TYPE_SNAPSHOT, + ZFS_TYPE_BOOKMARK, + ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK }; - default: - (void) fprintf(stderr, - gettext("invalid type '%s'\n"), - value); - usage(B_FALSE); - } + for (i = 0; i < ARRAY_SIZE(type_opts); ++i) + if (strcmp(tok, type_opts[i]) == 0) { + types |= type_types[i]; + goto found3; + } + + (void) fprintf(stderr, + gettext("invalid type '%s'\n"), tok); + usage(B_FALSE); +found3:; } break;