From 56c4f6fe724e4aa54498188873d84e5694b02984 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Mon, 12 Apr 2021 19:00:00 +0200 Subject: [PATCH] APPS: Allow duplicate entries in options list, marking them OPT_DUP Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15126) --- apps/include/opt.h | 1 + apps/lib/opt.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/include/opt.h b/apps/include/opt.h index 213e41b83b8..951557974b0 100644 --- a/apps/include/opt.h +++ b/apps/include/opt.h @@ -318,6 +318,7 @@ typedef struct options_st { } OPTIONS; /* Special retval values: */ #define OPT_PARAM 0 /* same as OPT_EOF usually defined in apps */ +#define OPT_DUP -2 /* marks duplicate occurrence of option in help output */ /* * 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 b0ec265aa90..0f08da2df44 100644 --- a/apps/lib/opt.c +++ b/apps/lib/opt.c @@ -187,7 +187,7 @@ char *opt_init(int ac, char **av, const OPTIONS *o) if (o->valtype == '.') OPENSSL_assert(o->retval == OPT_PARAM); else - OPENSSL_assert(o->retval > OPT_PARAM); + OPENSSL_assert(o->retval == OPT_DUP || o->retval > OPT_PARAM); switch (i) { case 0: case '-': case '.': case '/': case '<': case '>': case 'E': case 'F': @@ -203,8 +203,13 @@ char *opt_init(int ac, char **av, const OPTIONS *o) /* * Some compilers inline strcmp and the assert string is too long. */ - duplicated = strcmp(o->name, next->name) == 0; - OPENSSL_assert(!duplicated); + duplicated = next->retval != OPT_DUP + && strcmp(o->name, next->name) == 0; + if (duplicated) { + opt_printf_stderr("%s: Internal error: duplicate option %s\n", + prog, o->name); + OPENSSL_assert(!duplicated); + } } #endif if (o->name[0] == '\0') { -- 2.47.3