[openssl] master update
Richard Levitte
levitte at openssl.org
Tue Jun 2 07:46:56 UTC 2020
The branch master has been updated
via e306f83c8cfc7ac970d04a36c90634ab8573a594 (commit)
from 32df13497a1f1d7ef90a9c0b3128f65d18ab0086 (commit)
- Log -----------------------------------------------------------------
commit e306f83c8cfc7ac970d04a36c90634ab8573a594
Author: Richard Levitte <levitte at openssl.org>
Date: Thu May 28 13:53:48 2020 +0200
APPS: Remove make_config_name, use CONF_get1_default_config_file instead
Reviewed-by: Bernd Edlinger <bernd.edlinger at hotmail.de>
Reviewed-by: Tomas Mraz <tmraz at fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/11983)
-----------------------------------------------------------------------
Summary of changes:
apps/include/apps.h | 2 ++
apps/lib/apps.c | 20 ++++++++++++++------
apps/openssl.c | 26 ++++----------------------
crypto/conf/conf_mod.c | 14 ++++++--------
4 files changed, 26 insertions(+), 36 deletions(-)
diff --git a/apps/include/apps.h b/apps/include/apps.h
index b051222244..87d1b47150 100644
--- a/apps/include/apps.h
+++ b/apps/include/apps.h
@@ -15,6 +15,7 @@
# include "internal/sockets.h" /* for openssl_fdset() */
# include <assert.h>
+# include <stdarg.h>
# include <sys/types.h>
# ifndef OPENSSL_NO_POSIX_IO
# include <sys/stat.h>
@@ -179,6 +180,7 @@ typedef struct ca_db_st {
# endif
} CA_DB;
+void app_bail_out(char *fmt, ...);
void* app_malloc(int sz, const char *what);
BIGNUM *load_serial(const char *serialfile, int create, ASN1_INTEGER **retai);
int save_serial(const char *serialfile, const char *suffix, const BIGNUM *serial,
diff --git a/apps/lib/apps.c b/apps/lib/apps.c
index dbc9be344d..087ef4ec84 100644
--- a/apps/lib/apps.c
+++ b/apps/lib/apps.c
@@ -671,16 +671,24 @@ static int load_certs_crls(const char *file, int format,
return rv;
}
+void app_bail_out(char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ BIO_vprintf(bio_err, fmt, args);
+ va_end(args);
+ ERR_print_errors(bio_err);
+ exit(1);
+}
+
void* app_malloc(int sz, const char *what)
{
void *vp = OPENSSL_malloc(sz);
- if (vp == NULL) {
- BIO_printf(bio_err, "%s: Could not allocate %d bytes for %s\n",
- opt_getprog(), sz, what);
- ERR_print_errors(bio_err);
- exit(1);
- }
+ if (vp == NULL)
+ app_bail_out("%s: Could not allocate %d bytes for %s\n",
+ opt_getprog(), sz, what);
return vp;
}
diff --git a/apps/openssl.c b/apps/openssl.c
index 83c384fbfe..6265bffa67 100644
--- a/apps/openssl.c
+++ b/apps/openssl.c
@@ -80,27 +80,6 @@ static void apps_shutdown(void)
destroy_ui_method();
}
-static char *make_config_name(void)
-{
- const char *t;
- size_t len;
- char *p;
-
- if ((t = getenv("OPENSSL_CONF")) != NULL)
- return OPENSSL_strdup(t);
-
- t = X509_get_default_cert_area();
- len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1;
- p = app_malloc(len, "config filename buffer");
- strcpy(p, t);
-#ifndef OPENSSL_SYS_VMS
- strcat(p, "/");
-#endif
- strcat(p, OPENSSL_CONF);
-
- return p;
-}
-
#ifndef OPENSSL_NO_TRACE
typedef struct tracedata_st {
@@ -243,7 +222,6 @@ int main(int argc, char *argv[])
arg.size = 0;
/* Set up some of the environment. */
- default_config_file = make_config_name();
bio_in = dup_bio_in(FORMAT_TEXT);
bio_out = dup_bio_out(FORMAT_TEXT);
bio_err = dup_bio_err(FORMAT_TEXT);
@@ -279,6 +257,10 @@ int main(int argc, char *argv[])
}
pname = opt_progname(argv[0]);
+ default_config_file = CONF_get1_default_config_file();
+ if (default_config_file == NULL)
+ app_bail_out("%s: could not get default config file\n", pname);
+
/* first check the program name */
f.name = pname;
fp = lh_FUNCTION_retrieve(prog, &f);
diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c
index 504d9b181a..9d3db8eb31 100644
--- a/crypto/conf/conf_mod.c
+++ b/crypto/conf/conf_mod.c
@@ -516,25 +516,23 @@ void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data)
char *CONF_get1_default_config_file(void)
{
+ const char *t;
char *file, *sep = "";
- int len;
+ size_t size;
if ((file = ossl_safe_getenv("OPENSSL_CONF")) != NULL)
return OPENSSL_strdup(file);
- len = strlen(X509_get_default_cert_area());
+ t = X509_get_default_cert_area();
#ifndef OPENSSL_SYS_VMS
- len++;
sep = "/";
#endif
- len += strlen(OPENSSL_CONF);
-
- file = OPENSSL_malloc(len + 1);
+ size = strlen(t) + strlen(sep) + strlen(OPENSSL_CONF) + 1;
+ file = OPENSSL_malloc(size);
if (file == NULL)
return NULL;
- BIO_snprintf(file, len + 1, "%s%s%s", X509_get_default_cert_area(),
- sep, OPENSSL_CONF);
+ BIO_snprintf(file, size, "%s%s%s", t, sep, OPENSSL_CONF);
return file;
}
More information about the openssl-commits
mailing list