summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormiod <>2015-07-18 14:40:59 +0000
committermiod <>2015-07-18 14:40:59 +0000
commitfb4b9046bf049484f0a34a724bc5b6c7a17f967a (patch)
treec74957e7e8a714ac10a0f4f77da884dfd2183ae1 /src
parentdd1a8feef3ef54128aab53a720a711d669b98c21 (diff)
downloadopenbsd-fb4b9046bf049484f0a34a724bc5b6c7a17f967a.tar.gz
openbsd-fb4b9046bf049484f0a34a724bc5b6c7a17f967a.tar.bz2
openbsd-fb4b9046bf049484f0a34a724bc5b6c7a17f967a.zip
Check the return value of ASN1_STRING_set(), for it may fail to allocate
memory. Coverity CID 24810, 24846. ok bcook@ doug@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/asn1/asn1_gen.c13
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c7
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn1_gen.c13
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_doit.c7
4 files changed, 28 insertions, 12 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c
index 384088308f..08a5dec4a6 100644
--- a/src/lib/libcrypto/asn1/asn1_gen.c
+++ b/src/lib/libcrypto/asn1/asn1_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_gen.c,v 1.13 2015/02/12 06:04:24 jsg Exp $ */ 1/* $OpenBSD: asn1_gen.c,v 1.14 2015/07/18 14:40:59 miod Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -740,9 +740,14 @@ asn1_str2type(const char *str, int format, int utype)
740 atmp->value.asn1_string->length = rdlen; 740 atmp->value.asn1_string->length = rdlen;
741 atmp->value.asn1_string->type = utype; 741 atmp->value.asn1_string->type = utype;
742 742
743 } else if (format == ASN1_GEN_FORMAT_ASCII) 743 } else if (format == ASN1_GEN_FORMAT_ASCII) {
744 ASN1_STRING_set(atmp->value.asn1_string, str, -1); 744 if (ASN1_STRING_set(atmp->value.asn1_string, str,
745 else if ((format == ASN1_GEN_FORMAT_BITLIST) && 745 -1) == 0) {
746 ASN1err(ASN1_F_ASN1_STR2TYPE,
747 ERR_R_MALLOC_FAILURE);
748 goto bad_str;
749 }
750 } else if ((format == ASN1_GEN_FORMAT_BITLIST) &&
746 (utype == V_ASN1_BIT_STRING)) { 751 (utype == V_ASN1_BIT_STRING)) {
747 if (!CONF_parse_list(str, ',', 1, bitstr_cb, 752 if (!CONF_parse_list(str, ',', 1, bitstr_cb,
748 atmp->value.bit_string)) { 753 atmp->value.bit_string)) {
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index 5631d35712..d6fcaca745 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_doit.c,v 1.33 2015/07/15 17:44:20 miod Exp $ */ 1/* $OpenBSD: pk7_doit.c,v 1.34 2015/07/18 14:40:59 miod 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 *
@@ -850,12 +850,15 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
850 } else if (i == NID_pkcs7_digest) { 850 } else if (i == NID_pkcs7_digest) {
851 unsigned char md_data[EVP_MAX_MD_SIZE]; 851 unsigned char md_data[EVP_MAX_MD_SIZE];
852 unsigned int md_len; 852 unsigned int md_len;
853
853 if (!PKCS7_find_digest(&mdc, bio, 854 if (!PKCS7_find_digest(&mdc, bio,
854 OBJ_obj2nid(p7->d.digest->md->algorithm))) 855 OBJ_obj2nid(p7->d.digest->md->algorithm)))
855 goto err; 856 goto err;
856 if (!EVP_DigestFinal_ex(mdc, md_data, &md_len)) 857 if (!EVP_DigestFinal_ex(mdc, md_data, &md_len))
857 goto err; 858 goto err;
858 M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len); 859 if (M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data,
860 md_len) == 0)
861 goto err;
859 } 862 }
860 863
861 if (!PKCS7_is_detached(p7)) { 864 if (!PKCS7_is_detached(p7)) {
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_gen.c b/src/lib/libssl/src/crypto/asn1/asn1_gen.c
index 384088308f..08a5dec4a6 100644
--- a/src/lib/libssl/src/crypto/asn1/asn1_gen.c
+++ b/src/lib/libssl/src/crypto/asn1/asn1_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_gen.c,v 1.13 2015/02/12 06:04:24 jsg Exp $ */ 1/* $OpenBSD: asn1_gen.c,v 1.14 2015/07/18 14:40:59 miod Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -740,9 +740,14 @@ asn1_str2type(const char *str, int format, int utype)
740 atmp->value.asn1_string->length = rdlen; 740 atmp->value.asn1_string->length = rdlen;
741 atmp->value.asn1_string->type = utype; 741 atmp->value.asn1_string->type = utype;
742 742
743 } else if (format == ASN1_GEN_FORMAT_ASCII) 743 } else if (format == ASN1_GEN_FORMAT_ASCII) {
744 ASN1_STRING_set(atmp->value.asn1_string, str, -1); 744 if (ASN1_STRING_set(atmp->value.asn1_string, str,
745 else if ((format == ASN1_GEN_FORMAT_BITLIST) && 745 -1) == 0) {
746 ASN1err(ASN1_F_ASN1_STR2TYPE,
747 ERR_R_MALLOC_FAILURE);
748 goto bad_str;
749 }
750 } else if ((format == ASN1_GEN_FORMAT_BITLIST) &&
746 (utype == V_ASN1_BIT_STRING)) { 751 (utype == V_ASN1_BIT_STRING)) {
747 if (!CONF_parse_list(str, ',', 1, bitstr_cb, 752 if (!CONF_parse_list(str, ',', 1, bitstr_cb,
748 atmp->value.bit_string)) { 753 atmp->value.bit_string)) {
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
index 5631d35712..d6fcaca745 100644
--- a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_doit.c,v 1.33 2015/07/15 17:44:20 miod Exp $ */ 1/* $OpenBSD: pk7_doit.c,v 1.34 2015/07/18 14:40:59 miod 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 *
@@ -850,12 +850,15 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
850 } else if (i == NID_pkcs7_digest) { 850 } else if (i == NID_pkcs7_digest) {
851 unsigned char md_data[EVP_MAX_MD_SIZE]; 851 unsigned char md_data[EVP_MAX_MD_SIZE];
852 unsigned int md_len; 852 unsigned int md_len;
853
853 if (!PKCS7_find_digest(&mdc, bio, 854 if (!PKCS7_find_digest(&mdc, bio,
854 OBJ_obj2nid(p7->d.digest->md->algorithm))) 855 OBJ_obj2nid(p7->d.digest->md->algorithm)))
855 goto err; 856 goto err;
856 if (!EVP_DigestFinal_ex(mdc, md_data, &md_len)) 857 if (!EVP_DigestFinal_ex(mdc, md_data, &md_len))
857 goto err; 858 goto err;
858 M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len); 859 if (M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data,
860 md_len) == 0)
861 goto err;
859 } 862 }
860 863
861 if (!PKCS7_is_detached(p7)) { 864 if (!PKCS7_is_detached(p7)) {