Skip to content

Commit eeee3cb

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 18241c7 commit eeee3cb

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
@@ -2892,8 +2892,9 @@ int s_client_main(int argc, char **argv)
28922892
goto end;
28932893
}
28942894
atyp = ASN1_generate_nconf(genstr, cnf);
2895-
if (atyp == NULL) {
2895+
if (atyp == NULL || atyp->type != V_ASN1_SEQUENCE) {
28962896
NCONF_free(cnf);
2897+
ASN1_TYPE_free(atyp);
28972898
BIO_printf(bio_err, "ASN1_generate_nconf failed\n");
28982899
goto end;
28992900
}

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
@@ -1178,6 +1178,8 @@ ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
11781178
ASN1_TYPE *astype;
11791179
if ((astype = get_attribute(sk, NID_pkcs9_messageDigest)) == NULL)
11801180
return NULL;
1181+
if (astype->type != V_ASN1_OCTET_STRING)
1182+
return NULL;
11811183
return astype->value.octet_string;
11821184
}
11831185

0 commit comments

Comments
 (0)