From 7867f430b4c15b94fccac9cd4829b811bbf7383b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 22 Jan 2022 23:33:44 +0100 Subject: [PATCH] zfs: get: only accept whole source for -s, not src[=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 | 51 ++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 5d7599d3e0..b7a26242b0 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -2088,38 +2088,27 @@ found: case 's': cb.cb_sources = 0; - while (*optarg != '\0') { - static char *source_subopts[] = { - "local", "default", "inherited", - "received", "temporary", "none", - NULL }; - switch (getsubopt(&optarg, source_subopts, - &value)) { - case 0: - cb.cb_sources |= ZPROP_SRC_LOCAL; - break; - case 1: - cb.cb_sources |= ZPROP_SRC_DEFAULT; - break; - case 2: - cb.cb_sources |= ZPROP_SRC_INHERITED; - break; - case 3: - cb.cb_sources |= ZPROP_SRC_RECEIVED; - break; - case 4: - cb.cb_sources |= ZPROP_SRC_TEMPORARY; - break; - case 5: - cb.cb_sources |= ZPROP_SRC_NONE; - break; - default: - (void) fprintf(stderr, - gettext("invalid source " - "'%s'\n"), value); - usage(B_FALSE); - } + for (char *tok; (tok = strsep(&optarg, ",")); ) { + static const char *const source_opt[] = { + "local", "default", + "inherited", "received", + "temporary", "none" }; + static const int source_flg[] = { + ZPROP_SRC_LOCAL, ZPROP_SRC_DEFAULT, + ZPROP_SRC_INHERITED, ZPROP_SRC_RECEIVED, + ZPROP_SRC_TEMPORARY, ZPROP_SRC_NONE }; + + for (i = 0; i < ARRAY_SIZE(source_opt); ++i) + if (strcmp(tok, source_opt[i]) == 0) { + cb.cb_sources |= source_flg[i]; + goto found2; + } + + (void) fprintf(stderr, + gettext("invalid source '%s'\n"), tok); + usage(B_FALSE); +found2:; } break;