If CONF_get_string returns NULL and we want to tolerate this

(e.g., use a default), we have to call ERR_clear_error().
This commit is contained in:
Bodo Möller 2000-12-15 16:59:49 +00:00
parent 3ac82faae5
commit 2c0d10123e
4 changed files with 112 additions and 20 deletions

View File

@ -442,7 +442,11 @@ int add_oid_section(BIO *err, LHASH *conf)
STACK_OF(CONF_VALUE) *sktmp; STACK_OF(CONF_VALUE) *sktmp;
CONF_VALUE *cnf; CONF_VALUE *cnf;
int i; int i;
if(!(p=CONF_get_string(conf,NULL,"oid_section"))) return 1; if(!(p=CONF_get_string(conf,NULL,"oid_section")))
{
ERR_clear_error();
return 1;
}
if(!(sktmp = CONF_get_section(conf, p))) { if(!(sktmp = CONF_get_section(conf, p))) {
BIO_printf(err, "problem loading oid section %s\n", p); BIO_printf(err, "problem loading oid section %s\n", p);
return 0; return 0;

View File

@ -523,6 +523,8 @@ bad:
if (conf != NULL) if (conf != NULL)
{ {
p=CONF_get_string(conf,NULL,"oid_file"); p=CONF_get_string(conf,NULL,"oid_file");
if (p == NULL)
ERR_clear_error();
if (p != NULL) if (p != NULL)
{ {
BIO *oid_bio; BIO *oid_bio;
@ -550,6 +552,8 @@ bad:
} }
randfile = CONF_get_string(conf, BASE_SECTION, "RANDFILE"); randfile = CONF_get_string(conf, BASE_SECTION, "RANDFILE");
if (randfile == NULL)
ERR_clear_error();
app_RAND_load_file(randfile, bio_err, 0); app_RAND_load_file(randfile, bio_err, 0);
in=BIO_new(BIO_s_file()); in=BIO_new(BIO_s_file());
@ -635,9 +639,13 @@ bad:
} }
f=CONF_get_string(conf,BASE_SECTION,ENV_PRESERVE); f=CONF_get_string(conf,BASE_SECTION,ENV_PRESERVE);
if (f == NULL)
ERR_clear_error();
if ((f != NULL) && ((*f == 'y') || (*f == 'Y'))) if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
preserve=1; preserve=1;
f=CONF_get_string(conf,BASE_SECTION,ENV_MSIE_HACK); f=CONF_get_string(conf,BASE_SECTION,ENV_MSIE_HACK);
if (f == NULL)
ERR_clear_error();
if ((f != NULL) && ((*f == 'y') || (*f == 'Y'))) if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
msie_hack=1; msie_hack=1;
@ -832,13 +840,19 @@ bad:
goto err; goto err;
} }
if (!extensions) if (!extensions)
{
extensions=CONF_get_string(conf,section,ENV_EXTENSIONS); extensions=CONF_get_string(conf,section,ENV_EXTENSIONS);
if(extensions) { if (!extensions)
ERR_clear_error();
}
if (extensions)
{
/* Check syntax of file */ /* Check syntax of file */
X509V3_CTX ctx; X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx); X509V3_set_ctx_test(&ctx);
X509V3_set_conf_lhash(&ctx, conf); X509V3_set_conf_lhash(&ctx, conf);
if(!X509V3_EXT_add_conf(conf, &ctx, extensions, NULL)) { if (!X509V3_EXT_add_conf(conf, &ctx, extensions, NULL))
{
BIO_printf(bio_err, BIO_printf(bio_err,
"Error Loading extension section %s\n", "Error Loading extension section %s\n",
extensions); extensions);
@ -851,6 +865,8 @@ bad:
{ {
startdate=CONF_get_string(conf,section, startdate=CONF_get_string(conf,section,
ENV_DEFAULT_STARTDATE); ENV_DEFAULT_STARTDATE);
if (startdate == NULL)
ERR_clear_error();
} }
if (startdate && !ASN1_UTCTIME_set_string(NULL,startdate)) if (startdate && !ASN1_UTCTIME_set_string(NULL,startdate))
{ {
@ -863,6 +879,8 @@ bad:
{ {
enddate=CONF_get_string(conf,section, enddate=CONF_get_string(conf,section,
ENV_DEFAULT_ENDDATE); ENV_DEFAULT_ENDDATE);
if (enddate == NULL)
ERR_clear_error();
} }
if (enddate && !ASN1_UTCTIME_set_string(NULL,enddate)) if (enddate && !ASN1_UTCTIME_set_string(NULL,enddate))
{ {
@ -1142,13 +1160,20 @@ bad:
/*****************************************************************/ /*****************************************************************/
if (gencrl) if (gencrl)
{ {
if(!crl_ext) crl_ext=CONF_get_string(conf,section,ENV_CRLEXT); if (!crl_ext)
if(crl_ext) { {
crl_ext=CONF_get_string(conf,section,ENV_CRLEXT);
if (!crl_ext)
ERR_clear_error();
}
if (crl_ext)
{
/* Check syntax of file */ /* Check syntax of file */
X509V3_CTX ctx; X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx); X509V3_set_ctx_test(&ctx);
X509V3_set_conf_lhash(&ctx, conf); X509V3_set_conf_lhash(&ctx, conf);
if(!X509V3_EXT_add_conf(conf, &ctx, crl_ext, NULL)) { if(!X509V3_EXT_add_conf(conf, &ctx, crl_ext, NULL))
{
BIO_printf(bio_err, BIO_printf(bio_err,
"Error Loading CRL extension section %s\n", "Error Loading CRL extension section %s\n",
crl_ext); crl_ext);

View File

@ -463,6 +463,8 @@ bad:
if (req_conf != NULL) if (req_conf != NULL)
{ {
p=CONF_get_string(req_conf,NULL,"oid_file"); p=CONF_get_string(req_conf,NULL,"oid_file");
if (p == NULL)
ERR_clear_error();
if (p != NULL) if (p != NULL)
{ {
BIO *oid_bio; BIO *oid_bio;
@ -484,15 +486,24 @@ bad:
} }
if(!add_oid_section(bio_err, req_conf)) goto end; if(!add_oid_section(bio_err, req_conf)) goto end;
if ((md_alg == NULL) && if (md_alg == NULL)
((p=CONF_get_string(req_conf,SECTION,"default_md")) != NULL)) {
p=CONF_get_string(req_conf,SECTION,"default_md");
if (p == NULL)
ERR_clear_error();
if (p != NULL)
{ {
if ((md_alg=EVP_get_digestbyname(p)) != NULL) if ((md_alg=EVP_get_digestbyname(p)) != NULL)
digest=md_alg; digest=md_alg;
} }
}
if (!extensions) if (!extensions)
{
extensions = CONF_get_string(req_conf, SECTION, V3_EXTENSIONS); extensions = CONF_get_string(req_conf, SECTION, V3_EXTENSIONS);
if (!extensions)
ERR_clear_error();
}
if (extensions) { if (extensions) {
/* Check syntax of file */ /* Check syntax of file */
X509V3_CTX ctx; X509V3_CTX ctx;
@ -506,12 +517,22 @@ bad:
} }
if(!passin) if(!passin)
{
passin = CONF_get_string(req_conf, SECTION, "input_password"); passin = CONF_get_string(req_conf, SECTION, "input_password");
if (!passin)
ERR_clear_error();
}
if(!passout) if(!passout)
{
passout = CONF_get_string(req_conf, SECTION, "output_password"); passout = CONF_get_string(req_conf, SECTION, "output_password");
if (!passout)
ERR_clear_error();
}
p = CONF_get_string(req_conf, SECTION, STRING_MASK); p = CONF_get_string(req_conf, SECTION, STRING_MASK);
if (!p)
ERR_clear_error();
if(p && !ASN1_STRING_set_default_mask_asc(p)) { if(p && !ASN1_STRING_set_default_mask_asc(p)) {
BIO_printf(bio_err, "Invalid global string mask setting %s\n", p); BIO_printf(bio_err, "Invalid global string mask setting %s\n", p);
@ -519,7 +540,11 @@ bad:
} }
if(!req_exts) if(!req_exts)
{
req_exts = CONF_get_string(req_conf, SECTION, REQ_EXTENSIONS); req_exts = CONF_get_string(req_conf, SECTION, REQ_EXTENSIONS);
if (!req_exts)
ERR_clear_error();
}
if(req_exts) { if(req_exts) {
/* Check syntax of file */ /* Check syntax of file */
X509V3_CTX ctx; X509V3_CTX ctx;
@ -597,6 +622,8 @@ bad:
if (EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA) if (EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA)
{ {
char *randfile = CONF_get_string(req_conf,SECTION,"RANDFILE"); char *randfile = CONF_get_string(req_conf,SECTION,"RANDFILE");
if (randfile == NULL)
ERR_clear_error();
app_RAND_load_file(randfile, bio_err, 0); app_RAND_load_file(randfile, bio_err, 0);
} }
} }
@ -604,6 +631,8 @@ bad:
if (newreq && (pkey == NULL)) if (newreq && (pkey == NULL))
{ {
char *randfile = CONF_get_string(req_conf,SECTION,"RANDFILE"); char *randfile = CONF_get_string(req_conf,SECTION,"RANDFILE");
if (randfile == NULL)
ERR_clear_error();
app_RAND_load_file(randfile, bio_err, 0); app_RAND_load_file(randfile, bio_err, 0);
if (inrand) if (inrand)
app_RAND_load_files(inrand); app_RAND_load_files(inrand);
@ -650,7 +679,11 @@ bad:
if (pkey == NULL) goto end; if (pkey == NULL) goto end;
if (keyout == NULL) if (keyout == NULL)
{
keyout=CONF_get_string(req_conf,SECTION,KEYFILE); keyout=CONF_get_string(req_conf,SECTION,KEYFILE);
if (keyout == NULL)
ERR_clear_error();
}
if (keyout == NULL) if (keyout == NULL)
{ {
@ -675,7 +708,12 @@ bad:
p=CONF_get_string(req_conf,SECTION,"encrypt_rsa_key"); p=CONF_get_string(req_conf,SECTION,"encrypt_rsa_key");
if (p == NULL) if (p == NULL)
{
ERR_clear_error();
p=CONF_get_string(req_conf,SECTION,"encrypt_key"); p=CONF_get_string(req_conf,SECTION,"encrypt_key");
if (p == NULL)
ERR_clear_error();
}
if ((p != NULL) && (strcmp(p,"no") == 0)) if ((p != NULL) && (strcmp(p,"no") == 0))
cipher=NULL; cipher=NULL;
if (nodes) cipher=NULL; if (nodes) cipher=NULL;
@ -983,6 +1021,8 @@ static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, int attribs)
char *tmp, *dn_sect,*attr_sect; char *tmp, *dn_sect,*attr_sect;
tmp=CONF_get_string(req_conf,SECTION,PROMPT); tmp=CONF_get_string(req_conf,SECTION,PROMPT);
if (tmp == NULL)
ERR_clear_error();
if((tmp != NULL) && !strcmp(tmp, "no")) no_prompt = 1; if((tmp != NULL) && !strcmp(tmp, "no")) no_prompt = 1;
dn_sect=CONF_get_string(req_conf,SECTION,DISTINGUISHED_NAME); dn_sect=CONF_get_string(req_conf,SECTION,DISTINGUISHED_NAME);
@ -1001,7 +1041,10 @@ static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, int attribs)
attr_sect=CONF_get_string(req_conf,SECTION,ATTRIBUTES); attr_sect=CONF_get_string(req_conf,SECTION,ATTRIBUTES);
if (attr_sect == NULL) if (attr_sect == NULL)
{
ERR_clear_error();
attr_sk=NULL; attr_sk=NULL;
}
else else
{ {
attr_sk=CONF_get_section(req_conf,attr_sect); attr_sk=CONF_get_section(req_conf,attr_sect);
@ -1076,11 +1119,17 @@ start: for (;;)
if ((nid=OBJ_txt2nid(type)) == NID_undef) goto start; if ((nid=OBJ_txt2nid(type)) == NID_undef) goto start;
sprintf(buf,"%s_default",v->name); sprintf(buf,"%s_default",v->name);
if ((def=CONF_get_string(req_conf,dn_sect,buf)) == NULL) if ((def=CONF_get_string(req_conf,dn_sect,buf)) == NULL)
{
ERR_clear_error();
def=""; def="";
}
sprintf(buf,"%s_value",v->name); sprintf(buf,"%s_value",v->name);
if ((value=CONF_get_string(req_conf,dn_sect,buf)) == NULL) if ((value=CONF_get_string(req_conf,dn_sect,buf)) == NULL)
{
ERR_clear_error();
value=NULL; value=NULL;
}
sprintf(buf,"%s_min",v->name); sprintf(buf,"%s_min",v->name);
min=(int)CONF_get_number(req_conf,dn_sect,buf); min=(int)CONF_get_number(req_conf,dn_sect,buf);
@ -1122,12 +1171,19 @@ start2: for (;;)
sprintf(buf,"%s_default",type); sprintf(buf,"%s_default",type);
if ((def=CONF_get_string(req_conf,attr_sect,buf)) if ((def=CONF_get_string(req_conf,attr_sect,buf))
== NULL) == NULL)
{
ERR_clear_error();
def=""; def="";
}
sprintf(buf,"%s_value",type); sprintf(buf,"%s_value",type);
if ((value=CONF_get_string(req_conf,attr_sect,buf)) if ((value=CONF_get_string(req_conf,attr_sect,buf))
== NULL) == NULL)
{
ERR_clear_error();
value=NULL; value=NULL;
}
sprintf(buf,"%s_min",type); sprintf(buf,"%s_min",type);
min=(int)CONF_get_number(req_conf,attr_sect,buf); min=(int)CONF_get_number(req_conf,attr_sect,buf);

View File

@ -498,8 +498,15 @@ bad:
,errorline,extfile); ,errorline,extfile);
goto end; goto end;
} }
if (!extsect && !(extsect = CONF_get_string(extconf, "default", if (!extsect)
"extensions"))) extsect = "default"; {
extsect = CONF_get_string(extconf, "default", "extensions");
if (!extsect)
{
ERR_clear_error();
extsect = "default";
}
}
X509V3_set_ctx_test(&ctx2); X509V3_set_ctx_test(&ctx2);
X509V3_set_conf_lhash(&ctx2, extconf); X509V3_set_conf_lhash(&ctx2, extconf);
if (!X509V3_EXT_add_conf(extconf, &ctx2, extsect, NULL)) if (!X509V3_EXT_add_conf(extconf, &ctx2, extsect, NULL))