diff options
| author | jsing <> | 2014-12-28 15:05:38 +0000 |
|---|---|---|
| committer | jsing <> | 2014-12-28 15:05:38 +0000 |
| commit | d345b4a19115367113a1e04f60a9282f1c3ba104 (patch) | |
| tree | 4af4ef5494ca8076b305e7be3a27591cc8d51f89 | |
| parent | d43a21e2dad4d24325d3d611478bf6d761a0ab72 (diff) | |
| download | openbsd-d345b4a19115367113a1e04f60a9282f1c3ba104.tar.gz openbsd-d345b4a19115367113a1e04f60a9282f1c3ba104.tar.bz2 openbsd-d345b4a19115367113a1e04f60a9282f1c3ba104.zip | |
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 '')
| -rw-r--r-- | src/usr.bin/openssl/apps.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index c3bbab1684..506e421cc1 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: apps.c,v 1.16 2014/12/28 14:50:15 jsing Exp $ */ | 1 | /* $OpenBSD: apps.c,v 1.17 2014/12/28 15:05:38 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -2252,15 +2252,22 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) | |||
| 2252 | int i, j; | 2252 | int i, j; |
| 2253 | int fmt; | 2253 | int fmt; |
| 2254 | 2254 | ||
| 2255 | if (unnamed != NULL) | ||
| 2256 | *unnamed = NULL; | ||
| 2257 | |||
| 2255 | for (i = 1; i < argc; i++) { | 2258 | for (i = 1; i < argc; i++) { |
| 2256 | p = arg = argv[i]; | 2259 | p = arg = argv[i]; |
| 2257 | 2260 | ||
| 2261 | /* Single unnamed argument (without leading hyphen). */ | ||
| 2258 | if (*p++ != '-') { | 2262 | if (*p++ != '-') { |
| 2259 | if (unnamed == NULL) | 2263 | if (unnamed == NULL) |
| 2260 | goto unknown; | 2264 | goto unknown; |
| 2265 | if (*unnamed != NULL) | ||
| 2266 | goto toomany; | ||
| 2261 | *unnamed = arg; | 2267 | *unnamed = arg; |
| 2262 | continue; | 2268 | continue; |
| 2263 | } | 2269 | } |
| 2270 | |||
| 2264 | if (*p == '\0') /* XXX - end of named options. */ | 2271 | if (*p == '\0') /* XXX - end of named options. */ |
| 2265 | goto unknown; | 2272 | goto unknown; |
| 2266 | 2273 | ||
| @@ -2339,6 +2346,10 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) | |||
| 2339 | 2346 | ||
| 2340 | return (0); | 2347 | return (0); |
| 2341 | 2348 | ||
| 2349 | toomany: | ||
| 2350 | fprintf(stderr, "too many arguments\n"); | ||
| 2351 | return (1); | ||
| 2352 | |||
| 2342 | unknown: | 2353 | unknown: |
| 2343 | fprintf(stderr, "unknown option '%s'\n", arg); | 2354 | fprintf(stderr, "unknown option '%s'\n", arg); |
| 2344 | return (1); | 2355 | return (1); |
