]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
APPS: Allow duplicate entries in options list, marking them OPT_DUP
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Mon, 12 Apr 2021 17:00:00 +0000 (19:00 +0200)
committerDr. David von Oheimb <dev@ddvo.net>
Thu, 20 May 2021 14:31:22 +0000 (16:31 +0200)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15126)

apps/include/opt.h
apps/lib/opt.c

index 213e41b83b8ba9d640848f84a94d46baaddaab7d..951557974b066e308697e1482ca10a601186550a 100644 (file)
@@ -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
index b0ec265aa905b023940abaea6863a02a1d009626..0f08da2df441bb81fb6d5df38c943488fcb9c7c3 100644 (file)
@@ -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') {