From 45435f71dd8781c131b1cc4040113081296ee133 Mon Sep 17 00:00:00 2001 From: jsing Date: Sun, 28 Dec 2014 15:05:38 +0000 Subject: [PATCH] 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. --- usr.bin/openssl/apps.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 * @@ -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); -- 2.20.1