From da7f81d39308f9ecab6fde1f9116ff673ef3f3b3 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Tue, 16 May 2023 10:17:03 +0200 Subject: APPS: replace awkward and error-prone pattern by calls to new app_conf_try_string() Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale Reviewed-by: David von Oheimb (Merged from https://github.com/openssl/openssl/pull/20971) --- apps/lib/app_rand.c | 6 ++---- apps/lib/apps.c | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'apps/lib') diff --git a/apps/lib/app_rand.c b/apps/lib/app_rand.c index ad93858bfd..9691e71d7c 100644 --- a/apps/lib/app_rand.c +++ b/apps/lib/app_rand.c @@ -18,12 +18,10 @@ static STACK_OF(OPENSSL_STRING) *randfiles; void app_RAND_load_conf(CONF *c, const char *section) { - const char *randfile = NCONF_get_string(c, section, "RANDFILE"); + const char *randfile = app_conf_try_string(c, section, "RANDFILE"); - if (randfile == NULL) { - ERR_clear_error(); + if (randfile == NULL) return; - } if (RAND_load_file(randfile, -1) < 0) { BIO_printf(bio_err, "Can't load %s into RNG\n", randfile); ERR_print_errors(bio_err); diff --git a/apps/lib/apps.c b/apps/lib/apps.c index 4a749b0df3..bfa983a351 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -336,6 +336,20 @@ static char *app_get_pass(const char *arg, int keepbio) return OPENSSL_strdup(tpass); } +char *app_conf_try_string(const CONF *conf, const char *group, const char *name) +{ + char *res; + + ERR_set_mark(); + res = NCONF_get_string(conf, group, name); + if (res == NULL) + ERR_pop_to_mark(); + else + ERR_clear_last_mark(); + return res; +} + + CONF *app_load_config_bio(BIO *in, const char *filename) { long errorline = -1; @@ -416,10 +430,8 @@ int add_oid_section(CONF *conf) CONF_VALUE *cnf; int i; - if ((p = NCONF_get_string(conf, NULL, "oid_section")) == NULL) { - ERR_clear_error(); + if ((p = app_conf_try_string(conf, NULL, "oid_section")) == NULL) return 1; - } if ((sktmp = NCONF_get_section(conf, p)) == NULL) { BIO_printf(bio_err, "problem loading oid section %s\n", p); return 0; @@ -1684,12 +1696,11 @@ CA_DB *load_index(const char *dbfile, DB_ATTR *db_attr) else retdb->attributes.unique_subject = 1; - if (dbattr_conf) { - char *p = NCONF_get_string(dbattr_conf, NULL, "unique_subject"); + if (dbattr_conf != NULL) { + char *p = app_conf_try_string(dbattr_conf, NULL, "unique_subject"); - if (p) { + if (p != NULL) retdb->attributes.unique_subject = parse_yesno(p, 1); - } } retdb->dbfname = OPENSSL_strdup(dbfile); -- cgit v1.2.3