diff options
| author | miod <> | 2014-07-10 21:40:59 +0000 |
|---|---|---|
| committer | miod <> | 2014-07-10 21:40:59 +0000 |
| commit | c99ec4c1c37261359267882a1c4fc78b3022a6b6 (patch) | |
| tree | 6aa39ccd3cabdc1887e9f7cd7c39fd94dbf3832e /src | |
| parent | a8df8788ad3c4dfac45f2fbbbfd96d6cfc73f39a (diff) | |
| download | openbsd-c99ec4c1c37261359267882a1c4fc78b3022a6b6.tar.gz openbsd-c99ec4c1c37261359267882a1c4fc78b3022a6b6.tar.bz2 openbsd-c99ec4c1c37261359267882a1c4fc78b3022a6b6.zip | |
Fix a double free in a can't-fail error path in PKCS7_decrypt(), by removing
the error path altogether and simplifying the local variables as a result.
joint work with jsing@; ok jsing@ tedu@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/pkcs7/pk7_smime.c | 16 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/pkcs7/pk7_smime.c | 16 |
2 files changed, 12 insertions, 20 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c index 5d174f7644..01734bdd1b 100644 --- a/src/lib/libcrypto/pkcs7/pk7_smime.c +++ b/src/lib/libcrypto/pkcs7/pk7_smime.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: pk7_smime.c,v 1.15 2014/06/29 17:05:36 jsing Exp $ */ | 1 | /* $OpenBSD: pk7_smime.c,v 1.16 2014/07/10 21: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. | 3 | * project. |
| 4 | */ | 4 | */ |
| @@ -551,25 +551,21 @@ PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags) | |||
| 551 | } | 551 | } |
| 552 | 552 | ||
| 553 | if (flags & PKCS7_TEXT) { | 553 | if (flags & PKCS7_TEXT) { |
| 554 | BIO *tmpbuf, *bread; | 554 | BIO *tmpbuf; |
| 555 | |||
| 555 | /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */ | 556 | /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */ |
| 556 | if (!(tmpbuf = BIO_new(BIO_f_buffer()))) { | 557 | if (!(tmpbuf = BIO_new(BIO_f_buffer()))) { |
| 557 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); | 558 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); |
| 558 | BIO_free_all(tmpmem); | 559 | BIO_free_all(tmpmem); |
| 559 | return 0; | 560 | return 0; |
| 560 | } | 561 | } |
| 561 | if (!(bread = BIO_push(tmpbuf, tmpmem))) { | 562 | BIO_push(tmpbuf, tmpmem); |
| 562 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); | 563 | ret = SMIME_text(tmpbuf, data); |
| 563 | BIO_free_all(tmpbuf); | ||
| 564 | BIO_free_all(tmpmem); | ||
| 565 | return 0; | ||
| 566 | } | ||
| 567 | ret = SMIME_text(bread, data); | ||
| 568 | if (ret > 0 && BIO_method_type(tmpmem) == BIO_TYPE_CIPHER) { | 564 | if (ret > 0 && BIO_method_type(tmpmem) == BIO_TYPE_CIPHER) { |
| 569 | if (!BIO_get_cipher_status(tmpmem)) | 565 | if (!BIO_get_cipher_status(tmpmem)) |
| 570 | ret = 0; | 566 | ret = 0; |
| 571 | } | 567 | } |
| 572 | BIO_free_all(bread); | 568 | BIO_free_all(tmpbuf); |
| 573 | return ret; | 569 | return ret; |
| 574 | } else { | 570 | } else { |
| 575 | for (;;) { | 571 | for (;;) { |
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c b/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c index 5d174f7644..01734bdd1b 100644 --- a/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c +++ b/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: pk7_smime.c,v 1.15 2014/06/29 17:05:36 jsing Exp $ */ | 1 | /* $OpenBSD: pk7_smime.c,v 1.16 2014/07/10 21: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. | 3 | * project. |
| 4 | */ | 4 | */ |
| @@ -551,25 +551,21 @@ PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags) | |||
| 551 | } | 551 | } |
| 552 | 552 | ||
| 553 | if (flags & PKCS7_TEXT) { | 553 | if (flags & PKCS7_TEXT) { |
| 554 | BIO *tmpbuf, *bread; | 554 | BIO *tmpbuf; |
| 555 | |||
| 555 | /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */ | 556 | /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */ |
| 556 | if (!(tmpbuf = BIO_new(BIO_f_buffer()))) { | 557 | if (!(tmpbuf = BIO_new(BIO_f_buffer()))) { |
| 557 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); | 558 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); |
| 558 | BIO_free_all(tmpmem); | 559 | BIO_free_all(tmpmem); |
| 559 | return 0; | 560 | return 0; |
| 560 | } | 561 | } |
| 561 | if (!(bread = BIO_push(tmpbuf, tmpmem))) { | 562 | BIO_push(tmpbuf, tmpmem); |
| 562 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); | 563 | ret = SMIME_text(tmpbuf, data); |
| 563 | BIO_free_all(tmpbuf); | ||
| 564 | BIO_free_all(tmpmem); | ||
| 565 | return 0; | ||
| 566 | } | ||
| 567 | ret = SMIME_text(bread, data); | ||
| 568 | if (ret > 0 && BIO_method_type(tmpmem) == BIO_TYPE_CIPHER) { | 564 | if (ret > 0 && BIO_method_type(tmpmem) == BIO_TYPE_CIPHER) { |
| 569 | if (!BIO_get_cipher_status(tmpmem)) | 565 | if (!BIO_get_cipher_status(tmpmem)) |
| 570 | ret = 0; | 566 | ret = 0; |
| 571 | } | 567 | } |
| 572 | BIO_free_all(bread); | 568 | BIO_free_all(tmpbuf); |
| 573 | return ret; | 569 | return ret; |
| 574 | } else { | 570 | } else { |
| 575 | for (;;) { | 571 | for (;;) { |
