summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authormiod <>2014-05-06 20:17:16 +0000
committermiod <>2014-05-06 20:17:16 +0000
commit531558b6463471463a153626220bcc84831d6389 (patch)
tree9e708e6b876db83605390facf86152c51ffa449a /src/lib
parenta017339f4bfe6d30dc0dcc877349d89ed75f58f5 (diff)
downloadopenbsd-531558b6463471463a153626220bcc84831d6389.tar.gz
openbsd-531558b6463471463a153626220bcc84831d6389.tar.bz2
openbsd-531558b6463471463a153626220bcc84831d6389.zip
Make sure PKCS7_get_octet_string() return values are checked for NULL.
Reported by David Ramos (and simultaneously to OpenSSL as PR#3339). ok beck@ logan@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c12
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_doit.c12
2 files changed, 20 insertions, 4 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index 936226d736..5aa4a914cf 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -639,10 +639,10 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
639 * EOF and encode the last few bytes */ 639 * EOF and encode the last few bytes */
640 BIO_set_mem_eof_return(bio,0); 640 BIO_set_mem_eof_return(bio,0);
641 641
642 if (data_body->length > 0) 642 if (data_body != NULL && data_body->length > 0)
643 BIO_write(bio,(char *)data_body->data,data_body->length); 643 BIO_write(bio,(char *)data_body->data,data_body->length);
644#else 644#else
645 if (data_body->length > 0) 645 if (data_body != NULL && data_body->length > 0)
646 bio = BIO_new_mem_buf(data_body->data,data_body->length); 646 bio = BIO_new_mem_buf(data_body->data,data_body->length);
647 else { 647 else {
648 bio=BIO_new(BIO_s_mem()); 648 bio=BIO_new(BIO_s_mem());
@@ -788,6 +788,10 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
788 case NID_pkcs7_signed: 788 case NID_pkcs7_signed:
789 si_sk=p7->d.sign->signer_info; 789 si_sk=p7->d.sign->signer_info;
790 os=PKCS7_get_octet_string(p7->d.sign->contents); 790 os=PKCS7_get_octet_string(p7->d.sign->contents);
791 if (os == NULL) {
792 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_DECODE_ERROR);
793 goto err;
794 }
791 /* If detached data then the content is excluded */ 795 /* If detached data then the content is excluded */
792 if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) { 796 if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) {
793 M_ASN1_OCTET_STRING_free(os); 797 M_ASN1_OCTET_STRING_free(os);
@@ -797,6 +801,10 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
797 801
798 case NID_pkcs7_digest: 802 case NID_pkcs7_digest:
799 os=PKCS7_get_octet_string(p7->d.digest->contents); 803 os=PKCS7_get_octet_string(p7->d.digest->contents);
804 if (os == NULL) {
805 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_DECODE_ERROR);
806 goto err;
807 }
800 /* If detached data then the content is excluded */ 808 /* If detached data then the content is excluded */
801 if(PKCS7_type_is_data(p7->d.digest->contents) && p7->detached) 809 if(PKCS7_type_is_data(p7->d.digest->contents) && p7->detached)
802 { 810 {
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
index 936226d736..5aa4a914cf 100644
--- a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
@@ -639,10 +639,10 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
639 * EOF and encode the last few bytes */ 639 * EOF and encode the last few bytes */
640 BIO_set_mem_eof_return(bio,0); 640 BIO_set_mem_eof_return(bio,0);
641 641
642 if (data_body->length > 0) 642 if (data_body != NULL && data_body->length > 0)
643 BIO_write(bio,(char *)data_body->data,data_body->length); 643 BIO_write(bio,(char *)data_body->data,data_body->length);
644#else 644#else
645 if (data_body->length > 0) 645 if (data_body != NULL && data_body->length > 0)
646 bio = BIO_new_mem_buf(data_body->data,data_body->length); 646 bio = BIO_new_mem_buf(data_body->data,data_body->length);
647 else { 647 else {
648 bio=BIO_new(BIO_s_mem()); 648 bio=BIO_new(BIO_s_mem());
@@ -788,6 +788,10 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
788 case NID_pkcs7_signed: 788 case NID_pkcs7_signed:
789 si_sk=p7->d.sign->signer_info; 789 si_sk=p7->d.sign->signer_info;
790 os=PKCS7_get_octet_string(p7->d.sign->contents); 790 os=PKCS7_get_octet_string(p7->d.sign->contents);
791 if (os == NULL) {
792 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_DECODE_ERROR);
793 goto err;
794 }
791 /* If detached data then the content is excluded */ 795 /* If detached data then the content is excluded */
792 if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) { 796 if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) {
793 M_ASN1_OCTET_STRING_free(os); 797 M_ASN1_OCTET_STRING_free(os);
@@ -797,6 +801,10 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
797 801
798 case NID_pkcs7_digest: 802 case NID_pkcs7_digest:
799 os=PKCS7_get_octet_string(p7->d.digest->contents); 803 os=PKCS7_get_octet_string(p7->d.digest->contents);
804 if (os == NULL) {
805 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_DECODE_ERROR);
806 goto err;
807 }
800 /* If detached data then the content is excluded */ 808 /* If detached data then the content is excluded */
801 if(PKCS7_type_is_data(p7->d.digest->contents) && p7->detached) 809 if(PKCS7_type_is_data(p7->d.digest->contents) && p7->detached)
802 { 810 {