From 5c653870ec5357c65dc7d975a8c34619d9da0566 Mon Sep 17 00:00:00 2001 From: Paul Dagnelie Date: Tue, 17 Jan 2017 17:02:00 -0800 Subject: [PATCH] 7742 zfs send wrong error message with invalid long opts Reviewed by: Dan Kimmel Reviewed by: Steve Gonczi Reviewed by: Robert Mustacchi Approved by: Dan McDonald --- usr/src/cmd/zfs/zfs_main.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/usr/src/cmd/zfs/zfs_main.c b/usr/src/cmd/zfs/zfs_main.c index a9432a6eef..78dfeea98b 100644 --- a/usr/src/cmd/zfs/zfs_main.c +++ b/usr/src/cmd/zfs/zfs_main.c @@ -3769,15 +3769,42 @@ zfs_do_send(int argc, char **argv) flags.compress = B_TRUE; break; case ':': - (void) fprintf(stderr, gettext("missing argument for " - "'%c' option\n"), optopt); + /* + * If a parameter was not passed, optopt contains the + * value that would normally lead us into the + * appropriate case statement. If it's > 256, then this + * must be a longopt and we should look at argv to get + * the string. Otherwise it's just the character, so we + * should use it directly. + */ + if (optopt <= UINT8_MAX) { + (void) fprintf(stderr, + gettext("missing argument for '%c' " + "option\n"), optopt); + } else { + (void) fprintf(stderr, + gettext("missing argument for '%s' " + "option\n"), argv[optind - 1]); + } usage(B_FALSE); break; case '?': /*FALLTHROUGH*/ default: - (void) fprintf(stderr, gettext("invalid option '%c'\n"), - optopt); + /* + * If an invalid flag was passed, optopt contains the + * character if it was a short flag, or 0 if it was a + * longopt. + */ + if (optopt != 0) { + (void) fprintf(stderr, + gettext("invalid option '%c'\n"), optopt); + } else { + (void) fprintf(stderr, + gettext("invalid option '%s'\n"), + argv[optind - 1]); + + } usage(B_FALSE); } } -- 2.11.4.GIT