summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2014-12-28 15:05:39 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2014-12-28 15:05:39 +0000
commit02b71739691e51e65d391c1a0a599f7a46e99116 (patch)
tree4b4d55d9d44aee014a1c2b1dad34206107b093c2 /usr.bin
parent93730f50be2bd522e952f9a7d887b2e7c64b0567 (diff)
Only accept a single unnamed argument - the existing behaviour is to
silently accept multiple unnamed arguments, ignoring all except the last. This behaviour was already inconsistent between openssl(1) applications; apply the principal of least surprise. This will also simplify the addition of upcoming functionality.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/openssl/apps.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/usr.bin/openssl/apps.c b/usr.bin/openssl/apps.c
index c3bbab16841..506e421cc12 100644
--- a/usr.bin/openssl/apps.c
+++ b/usr.bin/openssl/apps.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apps.c,v 1.16 2014/12/28 14:50:15 jsing Exp $ */
+/* $OpenBSD: apps.c,v 1.17 2014/12/28 15:05:38 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -2252,15 +2252,22 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed)
int i, j;
int fmt;
+ if (unnamed != NULL)
+ *unnamed = NULL;
+
for (i = 1; i < argc; i++) {
p = arg = argv[i];
+ /* Single unnamed argument (without leading hyphen). */
if (*p++ != '-') {
if (unnamed == NULL)
goto unknown;
+ if (*unnamed != NULL)
+ goto toomany;
*unnamed = arg;
continue;
}
+
if (*p == '\0') /* XXX - end of named options. */
goto unknown;
@@ -2339,6 +2346,10 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed)
return (0);
+toomany:
+ fprintf(stderr, "too many arguments\n");
+ return (1);
+
unknown:
fprintf(stderr, "unknown option '%s'\n", arg);
return (1);