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)
This commit is contained in:
Dr. David von Oheimb 2021-01-07 09:00:02 +01:00 committed by Dr. David von Oheimb
parent 046a7aaa5e
commit 3372039252
7 changed files with 32 additions and 32 deletions

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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) */

View File

@ -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()) {
if ((fname = "apps_startup", !apps_startup())
|| (fname = "prog_init", (prog = prog_init()) == NULL)) {
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) {
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++) {

View File

@ -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;
}