summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2019-04-14 16:43:49 +0000
committerjsing <>2019-04-14 16:43:49 +0000
commit4acca314105512e798b1f9100b50de7ced92d5cd (patch)
tree8dd0495f908cf9aec8e01599cbe91c14ca232633
parent65ad94378ef20d46464421595910b27561e089f3 (diff)
downloadopenbsd-4acca314105512e798b1f9100b50de7ced92d5cd.tar.gz
openbsd-4acca314105512e798b1f9100b50de7ced92d5cd.tar.bz2
openbsd-4acca314105512e798b1f9100b50de7ced92d5cd.zip
Avoid potential double-frees following EVP_CIPHER_CTX_copy().
In the case of a cipher with a custom copy control, if that control fails we may still have pointers that we do not own in the previously copied cipher data. Avoid potential double-frees by zeroing and freeing the copied cipher data in this case. Issue reported by Guido Vranken. ok tb@
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index a229901956..38605a6fe1 100644
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_enc.c,v 1.40 2019/03/17 18:07:41 tb Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.41 2019/04/14 16:43:49 jsing 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 *
@@ -674,8 +674,21 @@ EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
674 memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size); 674 memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
675 } 675 }
676 676
677 if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY) 677 if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY) {
678 return in->cipher->ctrl((EVP_CIPHER_CTX *)in, 678 if (!in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY,
679 EVP_CTRL_COPY, 0, out); 679 0, out)) {
680 /*
681 * If the custom copy control failed, assume that there
682 * may still be pointers copied in the cipher_data that
683 * we do not own. This may result in a leak from a bad
684 * custom copy control, but that's preferable to a
685 * double free...
686 */
687 freezero(out->cipher_data, in->cipher->ctx_size);
688 out->cipher_data = NULL;
689 return 0;
690 }
691 }
692
680 return 1; 693 return 1;
681} 694}