Skip to content

Commit

Permalink
APPS: remove spurious errors when certain config file entries are not…
Browse files Browse the repository at this point in the history
… 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 #21050)

(cherry picked from commit 1737fb8)
  • Loading branch information
DDvO committed Jun 14, 2023
1 parent 06ae946 commit c553c08
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
29 changes: 22 additions & 7 deletions apps/ca.c
Expand Up @@ -628,6 +628,8 @@ int ca_main(int argc, char **argv)

f = NCONF_get_string(conf, section, ENV_NAMEOPT);

if (f == NULL)
ERR_clear_error();
if (f != NULL) {
if (!set_nameopt(f)) {
BIO_printf(bio_err, "Invalid name options: \"%s\"\n", f);
Expand Down Expand Up @@ -785,8 +787,10 @@ int ca_main(int argc, char **argv)
/* We can have sections in the ext file */
if (extensions == NULL) {
extensions = NCONF_get_string(extfile_conf, "default", "extensions");
if (extensions == NULL)
if (extensions == NULL) {
ERR_clear_error();
extensions = "default";
}
}
}

Expand Down Expand Up @@ -824,6 +828,8 @@ int ca_main(int argc, char **argv)
char *tmp_email_dn = NULL;

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)
email_dn = 0;
}
Expand All @@ -839,6 +845,7 @@ int ca_main(int argc, char **argv)
if (NCONF_get_string(conf, section, ENV_RAND_SERIAL) != NULL) {
rand_ser = 1;
} else {
ERR_clear_error();
serialfile = lookup_conf(conf, section, ENV_SERIAL);
if (serialfile == NULL)
goto end;
Expand Down Expand Up @@ -908,8 +915,10 @@ int ca_main(int argc, char **argv)
}

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;
}
}
if (enddate == NULL && days == 0) {
BIO_printf(bio_err, "cannot lookup how many days to certify for\n");
Expand Down Expand Up @@ -1161,22 +1170,28 @@ int ca_main(int argc, char **argv)
}
}

if ((crlnumberfile = NCONF_get_string(conf, section, ENV_CRLNUMBER))
!= NULL)
crlnumberfile = NCONF_get_string(conf, section, ENV_CRLNUMBER);
if (crlnumberfile != NULL) {
if ((crlnumber = load_serial(crlnumberfile, NULL, 0, NULL))
== NULL) {
BIO_printf(bio_err, "error while loading CRL number\n");
goto end;
}
} else {
ERR_clear_error();
}

if (!crldays && !crlhours && !crlsec) {
if (!NCONF_get_number(conf, section,
ENV_DEFAULT_CRL_DAYS, &crldays))
ENV_DEFAULT_CRL_DAYS, &crldays)) {
ERR_clear_error();
crldays = 0;
}
if (!NCONF_get_number(conf, section,
ENV_DEFAULT_CRL_HOURS, &crlhours))
ENV_DEFAULT_CRL_HOURS, &crlhours)) {
ERR_clear_error();
crlhours = 0;
ERR_clear_error();
}
}
if ((crl_nextupdate == NULL) &&
(crldays == 0) && (crlhours == 0) && (crlsec == 0)) {
Expand Down
1 change: 1 addition & 0 deletions apps/cmp.c
Expand Up @@ -2148,6 +2148,7 @@ static char *conf_get_string(const CONF *src_conf, const char *groups,
while ((end = prev_item(groups, end)) != NULL) {
if ((res = NCONF_get_string(src_conf, opt_item, name)) != NULL)
return res;
ERR_clear_error();
}
return res;
}
Expand Down
3 changes: 3 additions & 0 deletions apps/lib/apps.c
Expand Up @@ -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");
if (p) {
retdb->attributes.unique_subject = parse_yesno(p, 1);
} else {
ERR_clear_error();
}

}

retdb->dbfname = OPENSSL_strdup(dbfile);
Expand Down
4 changes: 3 additions & 1 deletion apps/req.c
Expand Up @@ -635,8 +635,10 @@ int req_main(int argc, char **argv)
if (newreq && pkey == NULL) {
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;
}

genctx = set_keygen_ctx(keyalg, &keyalgstr, &newkey_len, gen_eng);
if (genctx == NULL)
Expand Down

0 comments on commit c553c08

Please sign in to comment.