Skip to content

Commit 2502e7b

Browse files
bob-beckjogme
authored andcommitted
Ensure ASN1 types are checked before use.
Some of these were fixed by LibreSSL in commit openbsd/src@aa1f637 this fix includes the other fixes in that commit, as well as fixes for others found by a scan for a similar unvalidated access paradigm in the tree. Reviewed-by: Kurt Roeckx <kurt@roeckx.be> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from #29582)
1 parent 8f55936 commit 2502e7b

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

apps/s_client.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2894,8 +2894,9 @@ int s_client_main(int argc, char **argv)
28942894
goto end;
28952895
}
28962896
atyp = ASN1_generate_nconf(genstr, cnf);
2897-
if (atyp == NULL) {
2897+
if (atyp == NULL || atyp->type != V_ASN1_SEQUENCE) {
28982898
NCONF_free(cnf);
2899+
ASN1_TYPE_free(atyp);
28992900
BIO_printf(bio_err, "ASN1_generate_nconf failed\n");
29002901
goto end;
29012902
}

crypto/pkcs12/p12_kiss.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,17 @@ static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
196196
ASN1_BMPSTRING *fname = NULL;
197197
ASN1_OCTET_STRING *lkid = NULL;
198198

199-
if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_friendlyName)))
199+
if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_friendlyName))) {
200+
if (attrib->type != V_ASN1_BMPSTRING)
201+
return 0;
200202
fname = attrib->value.bmpstring;
203+
}
201204

202-
if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_localKeyID)))
205+
if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_localKeyID))) {
206+
if (attrib->type != V_ASN1_OCTET_STRING)
207+
return 0;
203208
lkid = attrib->value.octet_string;
209+
}
204210

205211
switch (PKCS12_SAFEBAG_get_nid(bag)) {
206212
case NID_keyBag:

crypto/pkcs7/pk7_doit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,8 @@ ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
12291229
ASN1_TYPE *astype;
12301230
if ((astype = get_attribute(sk, NID_pkcs9_messageDigest)) == NULL)
12311231
return NULL;
1232+
if (astype->type != V_ASN1_OCTET_STRING)
1233+
return NULL;
12321234
return astype->value.octet_string;
12331235
}
12341236

0 commit comments

Comments
 (0)