From 601fe8e0d78d4344445cbfa83dbe9bc4ad1287f1 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Sat, 3 Apr 2021 16:03:21 +0200 Subject: [PATCH] APPS: Allow non-option parameters appear anywhere in list, marking them OPT_PARAM Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15126) --- apps/include/opt.h | 2 ++ apps/lib/opt.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/include/opt.h b/apps/include/opt.h index 5d85877301..213e41b83b 100644 --- a/apps/include/opt.h +++ b/apps/include/opt.h @@ -316,6 +316,8 @@ typedef struct options_st { int valtype; const char *helpstr; } OPTIONS; +/* Special retval values: */ +#define OPT_PARAM 0 /* same as OPT_EOF usually defined in apps */ /* * A string/int pairing; widely use for option value lookup, hence the diff --git a/apps/lib/opt.c b/apps/lib/opt.c index 4b75b46681..b0ec265aa9 100644 --- a/apps/lib/opt.c +++ b/apps/lib/opt.c @@ -184,9 +184,13 @@ char *opt_init(int ac, char **av, const OPTIONS *o) /* Make sure options are legit. */ OPENSSL_assert(o->name[0] != '-'); - OPENSSL_assert(o->retval > 0); + if (o->valtype == '.') + OPENSSL_assert(o->retval == OPT_PARAM); + else + OPENSSL_assert(o->retval > OPT_PARAM); switch (i) { - case 0: case '-': case '/': case '<': case '>': case 'E': case 'F': + case 0: case '-': case '.': + case '/': case '<': case '>': case 'E': case 'F': case 'M': case 'U': case 'f': case 'l': case 'n': case 'p': case 's': case 'u': case 'c': case ':': case 'N': break; @@ -821,6 +825,9 @@ int opt_next(void) case ':': /* Just a string. */ break; + case '.': + /* Parameters */ + break; case '/': if (opt_isdir(arg) > 0) break; -- 2.39.2