APPS: remove spurious errors when certain config file entries are not provided

This backports the functional essence of #20971.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/21050)

(cherry picked from commit 1737fb8f45)
This commit is contained in:
Dr. David von Oheimb 2023-05-15 19:59:16 +02:00 committed by Dr. David von Oheimb
parent 06ae946a41
commit c553c08232
4 changed files with 29 additions and 8 deletions

View File

@ -628,6 +628,8 @@ end_of_options:
f = NCONF_get_string(conf, section, ENV_NAMEOPT); f = NCONF_get_string(conf, section, ENV_NAMEOPT);
if (f == NULL)
ERR_clear_error();
if (f != NULL) { if (f != NULL) {
if (!set_nameopt(f)) { if (!set_nameopt(f)) {
BIO_printf(bio_err, "Invalid name options: \"%s\"\n", f); BIO_printf(bio_err, "Invalid name options: \"%s\"\n", f);
@ -785,8 +787,10 @@ end_of_options:
/* We can have sections in the ext file */ /* We can have sections in the ext file */
if (extensions == NULL) { if (extensions == NULL) {
extensions = NCONF_get_string(extfile_conf, "default", "extensions"); extensions = NCONF_get_string(extfile_conf, "default", "extensions");
if (extensions == NULL) if (extensions == NULL) {
ERR_clear_error();
extensions = "default"; extensions = "default";
}
} }
} }
@ -824,6 +828,8 @@ end_of_options:
char *tmp_email_dn = NULL; char *tmp_email_dn = NULL;
tmp_email_dn = NCONF_get_string(conf, section, ENV_DEFAULT_EMAIL_DN); tmp_email_dn = NCONF_get_string(conf, section, ENV_DEFAULT_EMAIL_DN);
if (tmp_email_dn == NULL)
ERR_clear_error();
if (tmp_email_dn != NULL && strcmp(tmp_email_dn, "no") == 0) if (tmp_email_dn != NULL && strcmp(tmp_email_dn, "no") == 0)
email_dn = 0; email_dn = 0;
} }
@ -839,6 +845,7 @@ end_of_options:
if (NCONF_get_string(conf, section, ENV_RAND_SERIAL) != NULL) { if (NCONF_get_string(conf, section, ENV_RAND_SERIAL) != NULL) {
rand_ser = 1; rand_ser = 1;
} else { } else {
ERR_clear_error();
serialfile = lookup_conf(conf, section, ENV_SERIAL); serialfile = lookup_conf(conf, section, ENV_SERIAL);
if (serialfile == NULL) if (serialfile == NULL)
goto end; goto end;
@ -908,8 +915,10 @@ end_of_options:
} }
if (days == 0) { if (days == 0) {
if (!NCONF_get_number(conf, section, ENV_DEFAULT_DAYS, &days)) if (!NCONF_get_number(conf, section, ENV_DEFAULT_DAYS, &days)) {
ERR_clear_error();
days = 0; days = 0;
}
} }
if (enddate == NULL && days == 0) { if (enddate == NULL && days == 0) {
BIO_printf(bio_err, "cannot lookup how many days to certify for\n"); BIO_printf(bio_err, "cannot lookup how many days to certify for\n");
@ -1161,22 +1170,28 @@ end_of_options:
} }
} }
if ((crlnumberfile = NCONF_get_string(conf, section, ENV_CRLNUMBER)) crlnumberfile = NCONF_get_string(conf, section, ENV_CRLNUMBER);
!= NULL) if (crlnumberfile != NULL) {
if ((crlnumber = load_serial(crlnumberfile, NULL, 0, NULL)) if ((crlnumber = load_serial(crlnumberfile, NULL, 0, NULL))
== NULL) { == NULL) {
BIO_printf(bio_err, "error while loading CRL number\n"); BIO_printf(bio_err, "error while loading CRL number\n");
goto end; goto end;
} }
} else {
ERR_clear_error();
}
if (!crldays && !crlhours && !crlsec) { if (!crldays && !crlhours && !crlsec) {
if (!NCONF_get_number(conf, section, if (!NCONF_get_number(conf, section,
ENV_DEFAULT_CRL_DAYS, &crldays)) ENV_DEFAULT_CRL_DAYS, &crldays)) {
ERR_clear_error();
crldays = 0; crldays = 0;
}
if (!NCONF_get_number(conf, section, if (!NCONF_get_number(conf, section,
ENV_DEFAULT_CRL_HOURS, &crlhours)) ENV_DEFAULT_CRL_HOURS, &crlhours)) {
ERR_clear_error();
crlhours = 0; crlhours = 0;
ERR_clear_error(); }
} }
if ((crl_nextupdate == NULL) && if ((crl_nextupdate == NULL) &&
(crldays == 0) && (crlhours == 0) && (crlsec == 0)) { (crldays == 0) && (crlhours == 0) && (crlsec == 0)) {

View File

@ -2148,6 +2148,7 @@ static char *conf_get_string(const CONF *src_conf, const char *groups,
while ((end = prev_item(groups, end)) != NULL) { while ((end = prev_item(groups, end)) != NULL) {
if ((res = NCONF_get_string(src_conf, opt_item, name)) != NULL) if ((res = NCONF_get_string(src_conf, opt_item, name)) != NULL)
return res; return res;
ERR_clear_error();
} }
return res; return res;
} }

View File

@ -1671,7 +1671,10 @@ CA_DB *load_index(const char *dbfile, DB_ATTR *db_attr)
char *p = NCONF_get_string(dbattr_conf, NULL, "unique_subject"); char *p = NCONF_get_string(dbattr_conf, NULL, "unique_subject");
if (p) { if (p) {
retdb->attributes.unique_subject = parse_yesno(p, 1); retdb->attributes.unique_subject = parse_yesno(p, 1);
} else {
ERR_clear_error();
} }
} }
retdb->dbfname = OPENSSL_strdup(dbfile); retdb->dbfname = OPENSSL_strdup(dbfile);

View File

@ -635,8 +635,10 @@ int req_main(int argc, char **argv)
if (newreq && pkey == NULL) { if (newreq && pkey == NULL) {
app_RAND_load_conf(req_conf, section); app_RAND_load_conf(req_conf, section);
if (!NCONF_get_number(req_conf, section, BITS, &newkey_len)) if (!NCONF_get_number(req_conf, section, BITS, &newkey_len)) {
ERR_clear_error();
newkey_len = DEFAULT_KEY_LENGTH; newkey_len = DEFAULT_KEY_LENGTH;
}
genctx = set_keygen_ctx(keyalg, &keyalgstr, &newkey_len, gen_eng); genctx = set_keygen_ctx(keyalg, &keyalgstr, &newkey_len, gen_eng);
if (genctx == NULL) if (genctx == NULL)