diff options
| author | schwarze <> | 2020-06-04 21:21:03 +0000 |
|---|---|---|
| committer | schwarze <> | 2020-06-04 21:21:03 +0000 |
| commit | be3505dc014b9b7022575b6fe4f9c78c2080281c (patch) | |
| tree | 2920ef908eabfe843f01bfd04a3aaf4eff0a1cec /src/lib/libcrypto/asn1/x_attrib.c | |
| parent | 249e70083469fe402a1366e4a02f52cb145be012 (diff) | |
| download | openbsd-be3505dc014b9b7022575b6fe4f9c78c2080281c.tar.gz openbsd-be3505dc014b9b7022575b6fe4f9c78c2080281c.tar.bz2 openbsd-be3505dc014b9b7022575b6fe4f9c78c2080281c.zip | |
When X509_ATTRIBUTE_create() receives an invalid NID (e.g., -1), return
failure rather than silently constructing a broken X509_ATTRIBUTE object
that might cause NULL pointer accesses later on. This matters because
X509_ATTRIBUTE_create() is used by documented API functions like
PKCS7_add_attribute(3) and the NID comes straight from the user.
This fixes a bug found while working on documentation.
OK tb@ and "thanks" bluhm@
Diffstat (limited to 'src/lib/libcrypto/asn1/x_attrib.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/x_attrib.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c index bb74a1b6c7..04816eab77 100644 --- a/src/lib/libcrypto/asn1/x_attrib.c +++ b/src/lib/libcrypto/asn1/x_attrib.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: x_attrib.c,v 1.13 2015/02/14 14:56:45 jsing Exp $ */ | 1 | /* $OpenBSD: x_attrib.c,v 1.14 2020/06/04 21:21:03 schwarze Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -174,10 +174,13 @@ X509_ATTRIBUTE_create(int nid, int atrtype, void *value) | |||
| 174 | { | 174 | { |
| 175 | X509_ATTRIBUTE *ret = NULL; | 175 | X509_ATTRIBUTE *ret = NULL; |
| 176 | ASN1_TYPE *val = NULL; | 176 | ASN1_TYPE *val = NULL; |
| 177 | ASN1_OBJECT *oid; | ||
| 177 | 178 | ||
| 179 | if ((oid = OBJ_nid2obj(nid)) == NULL) | ||
| 180 | return (NULL); | ||
| 178 | if ((ret = X509_ATTRIBUTE_new()) == NULL) | 181 | if ((ret = X509_ATTRIBUTE_new()) == NULL) |
| 179 | return (NULL); | 182 | return (NULL); |
| 180 | ret->object = OBJ_nid2obj(nid); | 183 | ret->object = oid; |
| 181 | ret->single = 0; | 184 | ret->single = 0; |
| 182 | if ((ret->value.set = sk_ASN1_TYPE_new_null()) == NULL) | 185 | if ((ret->value.set = sk_ASN1_TYPE_new_null()) == NULL) |
| 183 | goto err; | 186 | goto err; |
