From c27363f566274a65067d7559f9669f300f957183 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Sun, 20 Aug 2017 17:10:48 -0400 Subject: Check # of arguments for remaining commands. Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/4201) --- apps/srp.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'apps/srp.c') diff --git a/apps/srp.c b/apps/srp.c index c5002188a5..ceb0640c2f 100644 --- a/apps/srp.c +++ b/apps/srp.c @@ -297,11 +297,12 @@ int srp_main(int argc, char **argv) "Exactly one of the options -add, -delete, -modify -list must be specified.\n"); goto opthelp; } - if ((mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD) - && argc < 1) { - BIO_printf(bio_err, - "Need at least one user for options -add, -delete, -modify. \n"); - goto opthelp; + if (mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD) { + if (argc == 0) { + BIO_printf(bio_err, "Need at least one user.\n"); + goto opthelp; + } + user = *argv++; } if ((passinarg != NULL || passoutarg != NULL) && argc != 1) { BIO_printf(bio_err, @@ -390,10 +391,7 @@ int srp_main(int argc, char **argv) if (verbose > 1) BIO_printf(bio_err, "Starting user processing\n"); - if (argc > 0) - user = *(argv++); - - while (mode == OPT_LIST || user) { + while (mode == OPT_LIST || user != NULL) { int userindex = -1; if (user != NULL && verbose > 1) @@ -554,9 +552,8 @@ int srp_main(int argc, char **argv) doupdatedb = 1; } } - if (--argc > 0) { - user = *(argv++); - } else { + user = *argv++; + if (user == NULL) { /* no more processing in any mode if no users left */ break; } -- cgit v1.2.3