Teach option parsing that a single hyphen denotes the end of named options
authorjsing <jsing@openbsd.org>
Sun, 28 Dec 2014 16:10:33 +0000 (16:10 +0000)
committerjsing <jsing@openbsd.org>
Sun, 28 Dec 2014 16:10:33 +0000 (16:10 +0000)
(as currently only implemented by some of the openssl(1) applications).

usr.bin/openssl/apps.c

index 7c774e4..4640519 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: apps.c,v 1.18 2014/12/28 15:48:52 jsing Exp $ */
+/* $OpenBSD: apps.c,v 1.19 2014/12/28 16:10:33 jsing Exp $ */
 /*
  * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
  *
@@ -2271,8 +2271,20 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed,
                        continue;
                }
 
-               if (*p == '\0') /* XXX - end of named options. */
+               /* End of named options (single hyphen). */
+               if (*p == '\0') {
+                       if (++i >= argc)
+                               goto done;
+                       if (argsused != NULL)
+                               goto done;
+                       if (unnamed != NULL && i == argc - 1) {
+                               if (*unnamed != NULL)
+                                       goto toomany;
+                               *unnamed = argv[i];
+                               continue;
+                       }
                        goto unknown;
+               }
 
                for (j = 0; opts[j].name != NULL; j++) {
                        opt = &opts[j];