diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2023-05-16 10:17:03 +0200 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2023-05-25 09:04:35 +0200 |
commit | da7f81d39308f9ecab6fde1f9116ff673ef3f3b3 (patch) | |
tree | 3f1b8310b685dc306c3ff266e552d96829ea1db0 /apps/lib | |
parent | c8aec16383c7a9aec76b28e6eb95d36bef6f7e56 (diff) |
APPS: replace awkward and error-prone pattern by calls to new app_conf_try_string()
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/20971)
Diffstat (limited to 'apps/lib')
-rw-r--r-- | apps/lib/app_rand.c | 6 | ||||
-rw-r--r-- | apps/lib/apps.c | 25 |
2 files changed, 20 insertions, 11 deletions
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); |