diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2021-01-07 09:00:02 +0100 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2021-01-11 19:39:49 +0100 |
commit | 3372039252c4d9c67de784a0fbdad5589991a347 (patch) | |
tree | 687417a67e1027ce1d90cd448b0b03b05a8e90df /apps | |
parent | apps/pkey.c: Forther improve user guidance, also on non-sensical option combi... (diff) | |
download | openssl-3372039252c4d9c67de784a0fbdad5589991a347.tar.xz openssl-3372039252c4d9c67de784a0fbdad5589991a347.zip |
APPS: Fix confusion between program and app/command name used in diagnostic/help output
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13799)
Diffstat (limited to 'apps')
-rw-r--r-- | apps/cmp.c | 6 | ||||
-rw-r--r-- | apps/dgst.c | 3 | ||||
-rw-r--r-- | apps/enc.c | 16 | ||||
-rw-r--r-- | apps/include/opt.h | 1 | ||||
-rw-r--r-- | apps/lib/opt.c | 10 | ||||
-rw-r--r-- | apps/openssl.c | 25 | ||||
-rw-r--r-- | apps/s_client.c | 3 |
7 files changed, 32 insertions, 32 deletions
diff --git a/apps/cmp.c b/apps/cmp.c index a484234f90..b28b7431ce 100644 --- a/apps/cmp.c +++ b/apps/cmp.c @@ -42,6 +42,7 @@ #include <openssl/objects.h> #include <openssl/x509.h> +static char *prog; static char *opt_config = NULL; #define CMP_SECTION "cmp" #define SECTION_NAME_MAX 40 /* max length of section name */ @@ -49,10 +50,6 @@ static char *opt_config = NULL; static char *opt_section = CMP_SECTION; static int opt_verbosity = OSSL_CMP_LOG_INFO; -#undef PROG -#define PROG cmp_main -static char *prog = "cmp"; - static int read_config(void); static CONF *conf = NULL; /* OpenSSL config file context structure */ @@ -2625,6 +2622,7 @@ int cmp_main(int argc, char **argv) int ret = 0; /* default: failure */ if (argc <= 1) { + prog = opt_appname(argv[0]); opt_help(cmp_options); goto err; } diff --git a/apps/dgst.c b/apps/dgst.c index 7110a97cf4..845c2eabc9 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -111,9 +111,8 @@ int dgst_main(int argc, char **argv) int engine_impl = 0; struct doall_dgst_digests dec; - prog = opt_progname(argv[0]); buf = app_malloc(BUFSIZE, "I/O buffer"); - md = EVP_get_digestbyname(prog); + md = EVP_get_digestbyname(argv[0]); prog = opt_init(argc, argv, dgst_options); while ((o = opt_next()) != OPT_EOF) { diff --git a/apps/enc.c b/apps/enc.c index f97621b1a6..42b14d4993 100644 --- a/apps/enc.c +++ b/apps/enc.c @@ -112,7 +112,7 @@ int enc_main(int argc, char **argv) const EVP_CIPHER *cipher = NULL, *c; const EVP_MD *dgst = NULL; char *hkey = NULL, *hiv = NULL, *hsalt = NULL, *p; - char *infile = NULL, *outfile = NULL, *prog; + char *infile = NULL, *outfile = NULL, *prog, *arg0; char *str = NULL, *passarg = NULL, *pass = NULL, *strbuf = NULL; char mbuf[sizeof(magic) - 1]; OPTION_CHOICE o; @@ -131,18 +131,18 @@ int enc_main(int argc, char **argv) BIO *bzl = NULL; #endif - /* first check the program name */ - prog = opt_progname(argv[0]); - if (strcmp(prog, "base64") == 0) { + /* first check the command name */ + arg0 = argv[0]; + if (strcmp(arg0, "base64") == 0) { base64 = 1; #ifdef ZLIB - } else if (strcmp(prog, "zlib") == 0) { + } else if (strcmp(arg0, "zlib") == 0) { do_zlib = 1; #endif } else { - cipher = EVP_get_cipherbyname(prog); - if (cipher == NULL && strcmp(prog, "enc") != 0) { - BIO_printf(bio_err, "%s is not a known cipher\n", prog); + cipher = EVP_get_cipherbyname(arg0); + if (cipher == NULL && strcmp(arg0, "enc") != 0) { + BIO_printf(bio_err, "%s is not a known cipher\n", arg0); goto end; } } diff --git a/apps/include/opt.h b/apps/include/opt.h index 56de57cf4c..15375e3a80 100644 --- a/apps/include/opt.h +++ b/apps/include/opt.h @@ -341,6 +341,7 @@ typedef struct string_int_pair_st { const char *opt_path_end(const char *filename); char *opt_progname(const char *argv0); +char *opt_appname(const char *arg0); char *opt_getprog(void); char *opt_init(int ac, char **av, const OPTIONS * o); int opt_next(void); diff --git a/apps/lib/opt.c b/apps/lib/opt.c index 260ff3b1c2..5ddf1c7a74 100644 --- a/apps/lib/opt.c +++ b/apps/lib/opt.c @@ -138,6 +138,15 @@ char *opt_progname(const char *argv0) } #endif +char *opt_appname(const char *arg0) +{ + size_t len = strlen(prog); + + if (arg0 != NULL) + snprintf(prog + len, sizeof(prog) - len - 1, " %s", arg0); + return prog; +} + char *opt_getprog(void) { return prog; @@ -151,7 +160,6 @@ char *opt_init(int ac, char **av, const OPTIONS *o) argv = av; opt_begin(); opts = o; - opt_progname(av[0]); unknown = NULL; /* Check all options up until the PARAM marker (if present) */ diff --git a/apps/openssl.c b/apps/openssl.c index e6746087ad..0c95a7585e 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -235,6 +235,7 @@ int main(int argc, char *argv[]) FUNCTION f, *fp; LHASH_OF(FUNCTION) *prog = NULL; char *pname; + const char *fname; ARGS arg; int ret = 0; @@ -249,9 +250,7 @@ int main(int argc, char *argv[]) #if defined(OPENSSL_SYS_VMS) && defined(__DECC) argv = copy_argv(&argc, argv); #elif defined(_WIN32) - /* - * Replace argv[] with UTF-8 encoded strings. - */ + /* Replace argv[] with UTF-8 encoded strings. */ win32_utf8argv(&argc, &argv); #endif @@ -259,18 +258,11 @@ int main(int argc, char *argv[]) setup_trace(getenv("OPENSSL_TRACE")); #endif - if (!apps_startup()) { - BIO_printf(bio_err, - "FATAL: Startup failure (dev note: apps_startup() failed)\n"); - ERR_print_errors(bio_err); - ret = 1; - goto end; - } - - prog = prog_init(); - if (prog == NULL) { + if ((fname = "apps_startup", !apps_startup()) + || (fname = "prog_init", (prog = prog_init()) == NULL)) { BIO_printf(bio_err, - "FATAL: Startup failure (dev note: prog_init() failed)\n"); + "FATAL: Startup failure (dev note: %s()) for %s\n", + fname, argv[0]); ERR_print_errors(bio_err); ret = 1; goto end; @@ -288,6 +280,9 @@ int main(int argc, char *argv[]) /* We assume we've been called as 'openssl cmd' */ argc--; argv++; + opt_appname(argv[0]); + } else { + argv[0] = pname; } /* If there's a command, run with that, otherwise "help". */ @@ -360,7 +355,7 @@ int help_main(int argc, char **argv) } calculate_columns(functions, &dc); - BIO_printf(bio_err, "Standard commands"); + BIO_printf(bio_err, "%s:\n\nStandard commands", prog); i = 0; tp = FT_none; for (fp = functions; fp->name != NULL; fp++) { diff --git a/apps/s_client.c b/apps/s_client.c index 56444baeca..25c01f4088 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -1010,7 +1010,6 @@ int s_client_main(int argc, char **argv) # endif #endif - prog = opt_progname(argv[0]); c_quiet = 0; c_debug = 0; c_showcerts = 0; @@ -1019,7 +1018,7 @@ int s_client_main(int argc, char **argv) cctx = SSL_CONF_CTX_new(); if (vpm == NULL || cctx == NULL) { - BIO_printf(bio_err, "%s: out of memory\n", prog); + BIO_printf(bio_err, "%s: out of memory\n", opt_getprog()); goto end; } |